[Lemon-user] lemon + glx
Alpár Jüttner
alpar at cs.elte.hu
Thu Jan 20 09:28:33 CET 2011
Hi,
> Dear all,
>
> I have troubles compiling some code which includes some of the lemon's
> headers when the openGL header <GL/glx.h> is included as well.
The culprit is /usr/include/X11/Xlib.h included by GL/glx.h and does the
following:
#define True 1
#define False 0
(Not to mention "#define Bool int" and "#define Status int"). We also
use the word True in LEMON:
namespace lemon {
struct True { };
}
It is correctly done in the lemon namespace. Still, assuming that
X11/Xlib.h has already been included, gcc will change it to
struct 1 { };
which is obviously wrong.
I would say this kind of littering of the global namespace is a very
irresponsible design failure of X11. We have heard about similar
problems with VS, but I thought the Un*x header files are more carefully
designed.
It's hard give you any good advice, but you basically have the following
choices:
* Change the order of the includes and be careful to never use
'True', 'False', 'Status' etc. in your own code, where 'etc'
means whatever X11 developers think useful to #define.
* Isolate (wrap around) X11. I.e. Create a separate
myglx.h/myglx.cc, and include GL/glx.h in myglx.cc only (but
basically nothing else). Implement wrapper API functions here to
all GL calls you want to use. Then, from the other parts of the
code, you won't use the standard GL API directly but only
through your own wrapper functions.
Regards,
Alpar
>
> Here is a simple example:
>
> #include <GL/glx.h>
> #include <lemon/smart_graph.h>
>
>
> int main(int argc, char* argv[])
> {
> std::cout << "Hello world." << std::endl;
>
> return 0;
> }
>
>
> When compiled using g++, without any compiler option, I obtain the
> following error:
>
> adrien at prunelli:~/Code/c-cpp/robotvision/testbed$ g++ -o lemon_glx lemon_glx.cpp
> In file included from /usr/local/include/lemon/core.h:26,
> from /usr/local/include/lemon/smart_graph.h:28,
> from lemon_glx.cpp:3:
> /usr/local/include/lemon/bits/enable_if.h:49: error: expected
> identifier before numeric constant
> /usr/local/include/lemon/bits/enable_if.h:49: error: expected
> unqualified-id before numeric constant
> /usr/local/include/lemon/bits/enable_if.h:59: error: expected
> identifier before numeric constant
> /usr/local/include/lemon/bits/enable_if.h:59: error: expected
> unqualified-id before numeric constant
> In file included from /usr/local/include/lemon/core.h:27,
> from /usr/local/include/lemon/smart_graph.h:28,
> from lemon_glx.cpp:3:
> /usr/local/include/lemon/bits/traits.h:156: error: expected
> unqualified-id before numeric constant
> /usr/local/include/lemon/bits/traits.h:169: error: expected
> unqualified-id before numeric constant
> /usr/local/include/lemon/bits/traits.h:183: error: expected
> unqualified-id before numeric constant
> /usr/local/include/lemon/bits/traits.h:198: error: expected
> unqualified-id before numeric constant
> In file included from /usr/local/include/lemon/bits/map_extender.h:27,
> from /usr/local/include/lemon/bits/graph_extender.h:24,
> from /usr/local/include/lemon/smart_graph.h:30,
> from lemon_glx.cpp:3:
> /usr/local/include/lemon/concepts/maps.h:157: error: expected
> unqualified-id before numeric constant
> In file included from /usr/local/include/lemon/bits/array_map.h:25,
> from /usr/local/include/lemon/bits/default_map.h:23,
> from /usr/local/include/lemon/bits/graph_extender.h:25,
> from /usr/local/include/lemon/smart_graph.h:30,
> from lemon_glx.cpp:3:
> /usr/local/include/lemon/bits/alteration_notifier.h:102: error:
> expected unqualified-id before numeric constant
> In file included from /usr/local/include/lemon/bits/default_map.h:23,
> from /usr/local/include/lemon/bits/graph_extender.h:25,
> from /usr/local/include/lemon/smart_graph.h:30,
> from lemon_glx.cpp:3:
> /usr/local/include/lemon/bits/array_map.h:54: error: expected
> unqualified-id before numeric constant
> In file included from /usr/local/include/lemon/bits/default_map.h:24,
> from /usr/local/include/lemon/bits/graph_extender.h:25,
> from /usr/local/include/lemon/smart_graph.h:30,
> from lemon_glx.cpp:3:
> /usr/local/include/lemon/bits/vector_map.h:63: error: expected
> unqualified-id before numeric constant
> In file included from /usr/local/include/lemon/smart_graph.h:30,
> from lemon_glx.cpp:3:
> /usr/local/include/lemon/bits/graph_extender.h:338: error: expected
> unqualified-id before numeric constant
> In file included from lemon_glx.cpp:3:
> /usr/local/include/lemon/smart_graph.h:66: error: expected
> unqualified-id before numeric constant
> /usr/local/include/lemon/smart_graph.h:67: error: expected
> unqualified-id before numeric constant
> /usr/local/include/lemon/smart_graph.h:472: error: expected
> unqualified-id before numeric constant
> /usr/local/include/lemon/smart_graph.h:473: error: expected
> unqualified-id before numeric constant
> /usr/local/include/lemon/smart_graph.h:474: error: expected
> unqualified-id before numeric constant
>
>
> If I invert the order of the 2 headers, then everything is fine.
>
>
> I'm using:
> - g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3
> - lemon1.2.1 (the one from the archive downloadable on the website)
> - the standard openGL headers which come with the ubuntu distribution 10.04
>
> Thanks a lot in advance for your help!
> Adrien
>
>
More information about the Lemon-user
mailing list