• Advertisement
Sign in to follow this  

gcc multiple definitions problem

This topic is 4307 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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++

Share this post


Link to post
Share on other sites
How about if you change their names? It should rule out some causes..

Share this post


Link to post
Share on other sites
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 *?!=!!!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
They should be placed in a CPP file, and in a header file you should declare them as extern.

cpp:

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

h:
extern PFNGLBINDBUFFERARBPROC glBindBufferARB;
extern PFNGLGENBUFFERSARBPROC glGenBuffersARB;
extern PFNGLBUFFERDATAARBPROC glBufferDataARB;
extern PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB;

Share this post


Link to post
Share on other sites
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 file
extern PFNGLBINDBUFFERARBPROC glBindBufferARB;
extern PFNGLGENBUFFERSARBPROC glGenBuffersARB;
extern PFNGLBUFFERDATAARBPROC glBufferDataARB;
extern PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB;

//in a source file
PFNGLBINDBUFFERARBPROC glBindBufferARB = NULL;
PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL;
PFNGLBUFFERDATAARBPROC glBufferDataARB = NULL;
PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = NULL;



Share this post


Link to post
Share on other sites
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 :-)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement