2014-01-16 34 views
0

我對小牛編譯OpenTTD。我所做的唯一更改是定義CXXFLAGS =「 - stdlib = stdC++」。鏈接時,我得到的是這樣的許多鏈接錯誤:鏈接返回「未定義的符號」對於那些在圖書館符號被鏈接

"std::string::compare(char const*) const", referenced from: 
    LoadTranslations() in game_text.o 
    IsSameScript(ContentInfo const*, bool, ScriptInfo*, Subdirectory) in script_scanner.o 
    "std::string::compare(unsigned long, unsigned long, char const*) const", referenced from: 
    LoadTranslations() in game_text.o 

但是,我知道,這些符號應該是的libstdC++,它被鏈接:

$ nm -a /usr/lib/libstdc++.dylib | c++filt | grep "std::string::compare" 
000000000002ed12 T std::string::compare(char const*) const 
000000000002ec02 T std::string::compare(std::string const&) const 
000000000002ed68 T std::string::compare(unsigned long, unsigned long, char const*) const 
000000000002ede6 T std::string::compare(unsigned long, unsigned long, char const*, unsigned long) const 
000000000002ec44 T std::string::compare(unsigned long, unsigned long, std::string const&) const 
000000000002eca4 T std::string::compare(unsigned long, unsigned long, std::string const&, unsigned long, unsigned long) const 

我知道的libstdC++被鏈接在,我可以看到-lstdC++在調用鏈接器(使用「使VERBOSE = 1」):

g++ -L/opt/local/lib -framework Cocoa 3rdparty/md5/md5.o <lots of .o files> video/cocoa/wnd_quickdraw.o -lstdc++ -lc -F/System/Library/Frameworks -framework Cocoa -framework Carbon -framework AudioUnit -framework AudioToolbox -lz -L/opt/local/lib -llzma -llzo2 -L/opt/local/lib -lpng15 -L/opt/local/lib -lfreetype -lz -lbz2 -L/opt/local/lib -licui18n -licuuc -licudata -licule -liculx -o openttd 

我使用鐺的當前版本:

Apple LLVM version 5.0 (clang-500.2.78) (based on LLVM 3.3svn) 
Target: x86_64-apple-darwin13.0.0 
Thread model: posix 

爲什麼沒有連接匹配了丟失的符號,在他們的libstdC++的定義?

編輯:我手動運行上述GCC命令,此時手動添加-stdlib = STDC++到命令行的端部,和它的工作得很好。我知道這個順序很重要,但哪個標誌會覆蓋早期的-stdlib = stdC++?

+0

的'-L'開關告訴鏈接器去尋找'的libstdC++''中有你的/ opt /本地/ lib'但'的libstdC++'可能是'在/ usr/lib'。 – alvits

回答

0

我知道這個順序很重要,但哪個標誌會覆蓋早先的-stdlib = stdC++?

在猜測,我希望鏘行爲像g++並增加了一些到鏈接器命令鏈接到標準庫。 g++所有指定的庫後增加-lstdc++,所以鏘可能默認或-lstdc++添加任何-lc++,這取決於你使用的stdlib值。它甚至可能會過濾掉任何-lstdc++你,指定它是否要添加-lc++所以如果你想鏘可靠地鏈接到正確的庫,你需要使用正確的選擇,而不是試圖通過手動-lstdc++

您可以將-v添加到clang命令中,它應該顯示它用來調用鏈接器的精確命令,包括隱式添加的所有選項。