Author Topic: Compiling Error version 0.70 and 0.75  (Read 7037 times)

rdesgagn

  • User
  • *
  • Posts: 4
Compiling Error version 0.70 and 0.75
« on: November 20, 2008, 11:12:37 AM »
Hello all,

             I'm encountering a problem compiling GNE 0.70 or 0.75.  It always stops and gives me an error when compiling EventThreads.cpp :
Code: [Select]
[ 28%] Building CXX object src/CMakeFiles/gnelib.dir/EventThread.o
/home/rdesgagn/gne/gnelib0.75/src/EventThread.cpp: In member function ‘void GNE::EventThread::setTimeout(int)’:
/home/rdesgagn/gne/gnelib0.75/src/EventThread.cpp:82: error: ‘INT_MAX’ was not declared in this scope
make[2]: *** [src/CMakeFiles/gnelib.dir/EventThread.o] Error 1
make[1]: *** [src/CMakeFiles/gnelib.dir/all] Error 2
make: *** [all] Error 2

I looked at the other files and INT_MAX is used so I will have problem.  I searched if INT_MAX is defined in any other files but no.  Can someone help me here ?

Thanks,

René

rdesgagn

  • User
  • *
  • Posts: 4
Re: Compiling Error version 0.70 and 0.75
« Reply #1 on: November 20, 2008, 01:06:08 PM »
I solved my problem by adding this definition in gneintern.h

Code: [Select]
#define INT_MAX 2147483647

Will it cause any problem to GNE ?

René

Gillius

  • Administrator
  • User
  • *****
  • Posts: 147
    • http://www.gillius.org/
Re: Compiling Error version 0.70 and 0.75
« Reply #2 on: November 20, 2008, 06:01:21 PM »
Well, that is interested that it ever compiled. If you #include <climits> in gneintern.h, does it compile then? We should use the INT_MAX provided by the compiler. Although, really I should look into replacing that code with std::numeric_limit instead, the "C++" way of doing it.

If you can confirm that climits works, and/or std::numeric_limits works on your machine, then I will commit a patch to the subversion repository right away.
Gillius
Gillius's Programming http://www.gillius.org/

rdesgagn

  • User
  • *
  • Posts: 4
Re: Compiling Error version 0.70 and 0.75
« Reply #3 on: November 24, 2008, 11:48:25 AM »
Hi Gillius,

              I tried both ways and it's by adding
Code: [Select]
#include <limits> to gneintern.h that works best.  By that, I mean no warning/error at all.  If you add
Code: [Select]
#include <climits> instead, you'll get a warning but it still works.  Here is the warning just in case you want it :

Code: [Select]
In file included from /home/rdesgagn/gne/gnelib0.75/src/ServerConnection.cpp:28:                                                                                                                                                             
/home/rdesgagn/gne/gnelib0.75/include/gnelib/EventThread.h:31:1: warning: "INT_MAX" redefined                                                                                                                                               
In file included from /usr/lib/gcc/i386-redhat-linux/4.3.0/../../../../include/c++/4.3.0/climits:48,                                                                                                                                         
                 from /home/rdesgagn/gne/gnelib0.75/src/gneintern.h:51,                                                                                                                                                                     
                 from /home/rdesgagn/gne/gnelib0.75/src/ServerConnection.cpp:20:                                                                                                                                                             
/usr/lib/gcc/i386-redhat-linux/4.3.0/include/limits.h:74:1: warning: this is the location of the previous definition                 

Thanks,

Rene

Gillius

  • Administrator
  • User
  • *****
  • Posts: 147
    • http://www.gillius.org/
Re: Compiling Error version 0.70 and 0.75
« Reply #4 on: November 24, 2008, 11:58:15 AM »
Is that an issue with GCC? limits is a C++ header, right? And climits is the C header normally for limits.h but for written for C++, I think. Man I've been doing Java for 4 years so my C++ is starting to get rusty.

I should also check on using std::numeric_limits<int> instead. I will work on this and do a commit today.
Gillius
Gillius's Programming http://www.gillius.org/

Gillius

  • Administrator
  • User
  • *****
  • Posts: 147
    • http://www.gillius.org/
Re: Compiling Error version 0.70 and 0.75
« Reply #5 on: November 24, 2008, 05:00:03 PM »
I should note that the current code compiles with the stock GCC 4.2.4 compiler in Ubuntu 8.04. I do think that my code is wrong for not including <climits>, but I also think that GCC 4.3 is broken in saying that the symbol is redefined if you do include climits. However, I ought not use C symbols in a C++ application anyway.

I'm also not sure why you didn't get warnings for PacketStream and Thread, which also used INT_MAX.

I've made a commit to SVN that still compiles for me on 4.2.4. I need to test it with visual studio. It should compile fine in 4.3 that you are using. Let me know how it goes.

I also need to update links on the GNE site.
Gillius
Gillius's Programming http://www.gillius.org/

rdesgagn

  • User
  • *
  • Posts: 4
Re: Compiling Error version 0.70 and 0.75
« Reply #6 on: November 24, 2008, 05:15:32 PM »
Hi Gillius,

             I know why I got the warning.  I added the #define INT_MAX 2147483647 which is not really good programming practise when I didn't know about <limits> and <climits> .  However, I noticed that Thread, PacketStream and EventThread include gneintern.h so I modified it (gneintern.h) to include <limits> which now works.   When recompiling, INT_MAX from <limits> is redefined in EventThread.cpp by my #define INT_MAX 2147483647.  To fix it, I removed the #define and that's it.  Thanks for your cooperation.

Rene

Gillius

  • Administrator
  • User
  • *****
  • Posts: 147
    • http://www.gillius.org/
Re: Compiling Error version 0.70 and 0.75
« Reply #7 on: November 24, 2008, 09:40:54 PM »
Well, if you are using version 0.75, try out the SVN version and it won't use the INT_MAX anymore (but it does use <limits>).

Thank you for not only finding this problem but helping me debug it. I wonder how long this issue has gone on. I will also probably work a little bit on the build documentation, because when I built this I pretty much had to start from scratch on remembering how to do it. Although, the build process is a lot easier with CMake... If anyone out there is still using the 0.70 release, try the SVN one.
Gillius
Gillius's Programming http://www.gillius.org/