Skip to main content
gamedev.net
🔒 Locked

gcc multiple definitions problem

Started by cignox1 10 replies 4.8k views
Original Post
cignox1
cignox1
Ok, as usual, the multiple definitions error appears when I don't expect it... Following the tutorials on the net, in order to use VBO with openGL I need to write the following functions definitions:

PFNGLBINDBUFFERARBPROC glBindBufferARB = NULL;
PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL;
PFNGLBUFFERDATAARBPROC glBufferDataARB = NULL;
PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = NULL;

Gcc doesn't like them, and complaints that all the three functions were already been defined in locale_facets.tcc.
Quote:
.objs\util.o: In function ZSt17__verify_groupingPKcjRKSs': C:/Programmi/CodeBlocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/c++/3.4.4/bits/locale_facets.tcc:2497: multiple definition of glBindBufferARB' .objs\main.o:C:/Programmi/CodeBlocks/bin/../lib/gcc/mingw32/3.4.4/../../../../include/c++/3.4.4/bits/locale_facets.tcc:2497: first defined here
I gave a look to this file, but wasn't able to find that string. What's wrong? Thank you.
MrEvil
MrEvil
Interesting, locale_facets.tcc has nothing to do with OpenGL!

The source here is:
/*2494*/  bool/*2495*/  __verify_grouping(const char* __grouping, size_t __grouping_size,/*2496*/		    const string& __grouping_tmp)/*2497*/  {/*2498*/    const size_t __n = __grouping_tmp.size() - 1;/*2499*/    const size_t __min = std::min(__n, __grouping_size - 1);/*2500*/    size_t __i = __n;/*2501*/    bool __test = true;/*2502*/    /*2503*/    // Parsed number groupings have to match the/*2504*/    // numpunct::grouping string exactly, starting at the


I have no idea how that might happen other than some sort of macro substitution going on somewhere. Maybe it's something to do with where you declared these things...

The internet seems to have very little to say about this problem.
smart_idiot
smart_idiot
Wierd.

Maybe GCC was hashing variable names internally for the sake of lookup and two things ended up with the same value. That's my only guess, and it's a long shot.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other
cignox1
cignox1
Yes, that file has nothing to do with openGL. One more strange thing is that if I comment out those definitions, the compiler says that the functions have not been declared :-(
I love C++
I hate C++
I love C++
MrEvil
MrEvil
How about if you change their names? It should rule out some causes..
cignox1
cignox1
I tried, but the result is the same: if I remove ARB from the names, it keeps to say that it was already defined.
I prefer not to use external libraries to load the extensions, because this is the first time I use them and would like to use the old way.
And this error makes me *?!=!!!
Nitage
Nitage
Is that in a source file or a header file?
bubu LV
bubu LV
Is PFNGLBINDBUFFERARBPROC defined somewhere?
cignox1
cignox1
Quote:
Original post by Nitage
Is that in a source file or a header file?


If I put them in a source file, then other sources may be unable to see them. In fact, if I put them in a cpp, the compiler tells me that when I try to use them they are undefined (I suppose that this is bound to the order of compilation?)

Quote:

Is PFNGLBINDBUFFERARBPROC defined somewhere?

Should be defined in the file glext.h, than I include from my own headers that need it.
Nitage
Nitage
Quote:
Original post by cignox1
Quote:
Original post by Nitage
Is that in a source file or a header file?


If I put them in a source file, then other sources may be unable to see them. In fact, if I put them in a cpp, the compiler tells me that when I try to use them they are undefined (I suppose that this is bound to the order of compilation?)



Then that's your problem. Every translation unit that includes the header will redefine the symbols, so the linker will fail.

You need to do this:

//In a header fileextern PFNGLBINDBUFFERARBPROC glBindBufferARB;extern PFNGLGENBUFFERSARBPROC glGenBuffersARB;extern PFNGLBUFFERDATAARBPROC glBufferDataARB;extern PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB;//in a source filePFNGLBINDBUFFERARBPROC glBindBufferARB = NULL;PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL;PFNGLBUFFERDATAARBPROC glBufferDataARB = NULL;PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = NULL;


cignox1
cignox1
Thank you all! Me stupid, that is what happens after having worked too much with Java!
By the way, using GL in immediate mode I render 10 times a ~45k polys model at 8fps. With vertex arrays I get 25fps. Using vbo I get 38fps.
Not bad improvement, really :-)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.