OSX CLI compilation woes

Started by
10 comments, last by Derakon 18 years ago
Somewhere along the line, I lost the ability to compile my projects (using Makefiles and g++, 'cause I like commandlines). They fail with the following output:
g++ -g -Wall -pedantic -Iinclude -I/usr/local/include/SDL -bind_at_load -o game main.o sprite.o coord.o generic.o animation.o 
world.o layer.o listener.o box.o spritetree.o polygon.o line.o -L/usr/local/lib 
-framework Cocoa -framework OpenGL -lSDLmain -lSDL -lSDL_image -lSDL_draw 
-llua -llualib -lvcontrol -lstdc++
ld: world.o illegal reference to symbol: 
std::_Rb_tree_rotate_left(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*&) 
defined in indirectly referenced dynamic library /usr/lib/libstdc++.6.dylib
make: *** [game] Error 1
Now, that seems to imply that my standard libraries got horked somehow. I've downloaded XTools 1.5 from the Apple website (I can't use the 2.0+ versions because they're OS 10.4 only, and I'm running 10.3), but it refuses to do a clean install; I can only "Upgrade" my components. This, sadly, does not result in a replacement of my stdlibs - the CLI tools "upgrade" is 0KB in size. Presumably it's checking for the existence but not the integrity of my libraries. Does anyone know how I might go about fixing this problem? Is my diagnosis even correct? I'm decent at programming, but my knowledge of how libraries work is sketchy at best. Google searches reveal that people who installed Google Earth had similar problems, but I haven't installed that program. The only thing significant I've installed lately is Blender, but it's been long enough since I tried working on my coding projects that I can't say for certain if it was Blender that broke things. [Edited by - Derakon on April 2, 2006 1:34:14 AM]
Jetblade: an open-source 2D platforming game in the style of Metroid and Castlevania, with procedurally-generated levels
Advertisement
Try adding the argument /usr/lib/libstdc++.6.dylib
Assuming you meant -l/usr/lib/libstdc++ (that's a lowercase 'L'), I just get "ld: can't locate file for: -l/usr/lib/libstdc++.6.dylib". Or for any of the variations on the name that I think it would want (e.g. leaving off the ".dylib" and/or the ".6". If I actually just put "/usr/lib/libstdc++.6.dylib" as an argument then `make` doesn't work and spews out some 1816 lines of error output, some of which I've copied below:
g++ -g -Wall -pedantic -Iinclude -I/usr/local/include/SDL -I/usr/lib/ -bind_at_load -o game main.o sprite.o coord.o generic.o animation.o world.o layer.o listener.o box.o spritetree.o polygon.o line.o -L/usr/lib -L/usr/local/lib -framework Cocoa -framework OpenGL -lSDLmain -lSDL -lSDL_image -lSDL_draw -llua -llualib -lvcontrol -lstdc++ /usr/lib/libstdc++.6.dylibld: warning multiple definitions of symbol std::wcout/usr/lib/libstdc++.a(globals.o) private external definition of std::wcout in section (__DATA,__data)/usr/lib/libstdc++.6.dylib(single module) definition of std::wcoutld: warning multiple definitions of symbol std::wclog/usr/lib/libstdc++.a(globals.o) private external definition of std::wclog in section (__DATA,__data)/usr/lib/libstdc++.6.dylib(single module) definition of std::wclogld: warning multiple definitions of symbol std::wcerr/usr/lib/libstdc++.a(globals.o) private external definition of std::wcerr in section (__DATA,__data)/usr/lib/libstdc++.6.dylib(single module) definition of std::wcerrld: warning multiple definitions of symbol std::wcin/usr/lib/libstdc++.a(globals.o) private external definition of std::wcin in section (__DATA,__data)/usr/lib/libstdc++.6.dylib(single module) definition of std::wcinld: warning multiple definitions of symbol std::cout/usr/lib/libstdc++.a(globals.o) private external definition of std::cout in section (__DATA,__data)/usr/lib/libstdc++.6.dylib(single module) definition of std::coutld: warning multiple definitions of symbol std::clog/usr/lib/libstdc++.a(globals.o) private external definition of std::clog in section (__DATA,__data)/usr/lib/libstdc++.6.dylib(single module) definition of std::clogld: warning multiple definitions of symbol std::cerr

That...looks like a problem.
Jetblade: an open-source 2D platforming game in the style of Metroid and Castlevania, with procedurally-generated levels
Quote:Original post by Derakon
Assuming you meant -l/usr/lib/libstdc++ (that's a lowercase 'L'), I just get "ld: can't locate file for: -l/usr/lib/libstdc++.6.dylib". Or for any of the variations on the name that I think it would want (e.g. leaving off the ".dylib" and/or the ".6".

No, I did mean without the -l.

Quote:
If I actually just put "/usr/lib/libstdc++.6.dylib" as an argument then `make` doesn't work and spews out some 1816 lines of error output, some of which I've copied below:
*** Source Snippet Removed ***
That...looks like a problem.


Hmm. Maybe try removing -lstdc++.
Well, regressing to the old days of counting the errors, that gets me down to 37 lines of error output, which I've copied below:
g++ -g -Wall -pedantic -Iinclude -I/usr/local/include/SDL -I/usr/lib/ -bind_at_load -o game main.o sprite.o coord.o generic.o animation.o world.o layer.o listener.o box.o spritetree.o polygon.o line.o -L/usr/lib -L/usr/local/lib -framework Cocoa -framework OpenGL -lSDLmain -lSDL -lSDL_image -lSDL_draw -llua -llualib -lvcontrol /usr/lib/libstdc++.6.dylibld: multiple definitions of symbol std::allocator<char>::allocator(std::allocator<char> const&)/usr/lib/libstdc++.6.dylib(single module) definition of std::allocator<char>::allocator(std::allocator<char> const&)/usr/lib/libstdc++.a(stl-inst.o) private external definition of std::allocator<char>::allocator(std::allocator<char> const&) in section (__TEXT,__text)ld: multiple definitions of symbol std::allocator<char>::allocator()/usr/lib/libstdc++.6.dylib(single module) definition of std::allocator<char>::allocator()/usr/lib/libstdc++.a(stl-inst.o) private external definition of std::allocator<char>::allocator() in section (__TEXT,__text)ld: multiple definitions of symbol std::allocator<char>::allocator(std::allocator<char> const&)/usr/lib/libstdc++.6.dylib(single module) definition of std::allocator<char>::allocator(std::allocator<char> const&)/usr/lib/libstdc++.a(stl-inst.o) private external definition of std::allocator<char>::allocator(std::allocator<char> const&) in section (__TEXT,__text)ld: multiple definitions of symbol std::allocator<char>::allocator()/usr/lib/libstdc++.6.dylib(single module) definition of std::allocator<char>::allocator()/usr/lib/libstdc++.a(stl-inst.o) private external definition of std::allocator<char>::allocator() in section (__TEXT,__text)ld: multiple definitions of symbol std::allocator<char>::~allocator()/usr/lib/libstdc++.6.dylib(single module) definition of std::allocator<char>::~allocator()/usr/lib/libstdc++.a(stl-inst.o) private external definition of std::allocator<char>::~allocator() in section (__TEXT,__text)ld: multiple definitions of symbol std::allocator<char>::~allocator()/usr/lib/libstdc++.6.dylib(single module) definition of std::allocator<char>::~allocator()/usr/lib/libstdc++.a(stl-inst.o) private external definition of std::allocator<char>::~allocator() in section (__TEXT,__text)ld: multiple definitions of symbol std::allocator<wchar_t>::allocator(std::allocator<wchar_t> const&)/usr/lib/libstdc++.6.dylib(single module) definition of std::allocator<wchar_t>::allocator(std::allocator<wchar_t> const&)/usr/lib/libstdc++.a(stl-inst.o) private external definition of std::allocator<wchar_t>::allocator(std::allocator<wchar_t> const&) in section (__TEXT,__text)ld: multiple definitions of symbol std::allocator<wchar_t>::allocator()/usr/lib/libstdc++.6.dylib(single module) definition of std::allocator<wchar_t>::allocator()/usr/lib/libstdc++.a(stl-inst.o) private external definition of std::allocator<wchar_t>::allocator() in section (__TEXT,__text)ld: multiple definitions of symbol std::allocator<wchar_t>::allocator(std::allocator<wchar_t> const&)/usr/lib/libstdc++.6.dylib(single module) definition of std::allocator<wchar_t>::allocator(std::allocator<wchar_t> const&)/usr/lib/libstdc++.a(stl-inst.o) private external definition of std::allocator<wchar_t>::allocator(std::allocator<wchar_t> const&) in section (__TEXT,__text)ld: multiple definitions of symbol std::allocator<wchar_t>::allocator()/usr/lib/libstdc++.6.dylib(single module) definition of std::allocator<wchar_t>::allocator()/usr/lib/libstdc++.a(stl-inst.o) private external definition of std::allocator<wchar_t>::allocator() in section (__TEXT,__text)ld: multiple definitions of symbol std::allocator<wchar_t>::~allocator()/usr/lib/libstdc++.6.dylib(single module) definition of std::allocator<wchar_t>::~allocator()/usr/lib/libstdc++.a(stl-inst.o) private external definition of std::allocator<wchar_t>::~allocator() in section (__TEXT,__text)ld: multiple definitions of symbol std::allocator<wchar_t>::~allocator()/usr/lib/libstdc++.6.dylib(single module) definition of std::allocator<wchar_t>::~allocator()/usr/lib/libstdc++.a(stl-inst.o) private external definition of std::allocator<wchar_t>::~allocator() in section (__TEXT,__text)
So what is this "/usr/lib/libstdc++.a(stl-inst.o)", do I need it, and if not, how do I get rid of it safely?

EDIT: commentary from someone on another forum: "Since you're using XCode 1.5, you're using gcc 3.3 (or at least, not 4.0). So it shouldn't be using libstdc++.6.dylib, but the static version libstdc++.a, try to put it in your project/explicitely specify it in the makefile and it could solve the problem. Otherwise I don't know what it could be."

So I tried that (explicitly invoking the static version), but then I'm just back where I started with an illegal reference to something in the dylib. So somehow, one of my other libraries is invoking the dylib and thereby causing my compiler to choke. Is there a way I can determine which library is doing this and stop it somehow?

[Edited by - Derakon on April 2, 2006 1:58:34 PM]
Jetblade: an open-source 2D platforming game in the style of Metroid and Castlevania, with procedurally-generated levels
Just a guess here, but try not short-circuiting the compiler by explicitly linking in the C++ standard libarry. If you invoke GCC using the 'g++' driver, it automatically pulls in the standard libarry (and the rest of the C++ runtime libraries) from the right place. If you start adding them explicitly to the command line, you could end up pulling in a different version that's not ABI-compatible.

Stephen M. Webb
Professional Free Software Developer

Bregma: that's what I was doing originally. Something else that I'm linking in is referring to the dynamic library, causing ld to choke. My g++/ld skills are not to the point where I can figure out even what ld is being asked to do, as it's invoked by g++; otherwise I might have some clue how to tell ld to not use dynamic libraries or something similar. I don't want dynamic linking anyway, as I eventually want to be able to distribute this as a standalone program (including all of the libraries it needs in the package).
Jetblade: an open-source 2D platforming game in the style of Metroid and Castlevania, with procedurally-generated levels
Quote:Original post by Derakon
Something else that I'm linking in is referring to the dynamic library, causing ld to choke.


Could it be one of the frameworks or explicit dylibs you're pulling in were built for 10.4?

You could always add a "-Wl,-M" to the g+++ command line to force ld to spew a linkmap. It does it to stdout, so redirect output into a log.

I'm assuming you're actually instantiating a std::map of some description in world.cpp.

Stephen M. Webb
Professional Free Software Developer

Yes, I am using maps in world.cpp. Adding the suggested arguments to my g++ flags just gets me a lot of "linker input file unused because linking not done" - one for each .o file and -l library, and one for libstdc++.a, of course. The invocation now looks like this:
g++ -g -Wall -pedantic -Iinclude -I/usr/local/include/SDL -bind_at_load -Wl -M -o game main.o sprite.o coord.o generic.o animation.o world.o layer.o listener.o box.o spritetree.o polygon.o line.o -L/usr/lib -L/usr/local/lib -framework Cocoa -framework OpenGL -lSDLmain -lSDL -lSDL_image -lSDL_draw -llua -llualib -lvcontrol /usr/lib/libstdc++.a



I feel like this is turning into Remedial Makefiles. Feel free to tell me to go read through the documentation if you think it'd help.
Jetblade: an open-source 2D platforming game in the style of Metroid and Castlevania, with procedurally-generated levels
Original post by Derakon
-Wl -M 

Make sure it's -Wl,-M with no space and with a comma. It's a passthrough arg to ld.
Quote:
I feel like this is turning into Remedial Makefiles. Feel free to tell me to go read through the documentation if you think it'd help.

Ah, no, I've read it. It doesn't seem to help.


Have you used otool on all the dylibs (including the ones on the frameworks) to check what version of libstdc++ they were built with?

Stephen M. Webb
Professional Free Software Developer

This topic is closed to new replies.

Advertisement