3

我对clang进行了apt-get-ed,这就是我尝试编译简单的2行程序时发生的情况:(我的机器上有g ++,IDK如果这是问题的原因)

clang teststring.cpp -v Ubuntu clang 版本 3.0-6ubuntu3 (tags/RELEASE_30/final) (基于 LLVM 3.0) 目标:i386-pc-linux-gnu 线程模型:posix "/usr/bin/clang" -cc1 -triple i386-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name teststring.cpp -mrelocation-model static -mdisable-fp-elim -masm-verbose - mconstructor-aliases -target-cpu pentium4 -target-linker-version 2.22 -momit-leaf-frame-pointer -v -resource-dir /usr/bin/../lib/clang/3.0 -fmodule-cache-path /var /tmp/clang-module-cache -internal-isystem /usr/include/c++/4.6 -internal-isystem /usr/include/c++/4.6/i686-linux-gnu -internal-isystem /usr/include/c++/4.6 /backward -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.0/include -internal-externc-isystem /usr/include/i686-linux-gnu -internal-externc-isystem /usr/include -fdeprecated-macro -ferror-limit 19 -fmessage-length 80 -fgnu-runtime -fobjc- runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/teststring-e3FNx4.o -x c++ teststring。 cpp clang -cc1 版本 3.0 基于 i386-pc-linux-gnu 上托管的 llvm 3.0 忽略不存在的目录“/usr/include/i686-linux-gnu” 忽略不存在的目录“/usr/include/c++/4.6//i686- linux-gnu/32" 忽略不存在的目录 "/usr/include/i686-linux-gnu/" 忽略不存在的目录 "/usr/include/i686-linux-gnu" 忽略重复的目录 "/usr/include/c++/4.6"忽略重复目录“/usr/include/c++/4.6/i686-linux-gnu" 忽略重复目录 "/usr/include/c++/4.6/backward" 忽略重复目录 "/usr/include/c++/4.6" 忽略重复目录"/usr/ include/c++/4.6/backward"忽略重复目录"/usr/include/c++/4.6"忽略重复目录"/usr/include/c++/4.6/i686-linux-gnu"忽略重复目录"/usr/include/c++ /4.6/backward”忽略重复目录“/usr/local/include”忽略重复目录“/usr/bin/../lib/clang/3.0/include”忽略重复目录“/usr/include”包含“... " 搜索从这里开始:include <...> 搜索从这里开始: /usr/include/c++/4.6 /usr/include/c++/4.6/i686-linux-gnu /usr/include/c++/4.6/backward6/i686-linux-gnu"忽略重复目录"/usr/include/c++/4.6/backward"忽略重复目录"/usr/include/c++/4.6"忽略重复目录"/usr/include/c++/4.6/backward "忽略重复目录"/usr/include/c++/4.6"忽略重复目录"/usr/include/c++/4.6/i686-linux-gnu"忽略重复目录"/usr/include/c++/4.6/backward"忽略重复目录 "/usr/local/include" 忽略重复目录 "/usr/bin/../lib/clang/3.0/include" 忽略重复目录 "/usr/include" include "..." 搜索从这里开始:include < ...> 从这里开始搜索:/usr/include/c++/4.6 /usr/include/c++/4.6/i686-linux-gnu /usr/include/c++/4.6/backward6/i686-linux-gnu"忽略重复目录"/usr/include/c++/4.6/backward"忽略重复目录"/usr/include/c++/4.6"忽略重复目录"/usr/include/c++/4.6/backward "忽略重复目录"/usr/include/c++/4.6"忽略重复目录"/usr/include/c++/4.6/i686-linux-gnu"忽略重复目录"/usr/include/c++/4.6/backward"忽略重复目录 "/usr/local/include" 忽略重复目录 "/usr/bin/../lib/clang/3.0/include" 忽略重复目录 "/usr/include" include "..." 搜索从这里开始:include < ...> 从这里开始搜索:/usr/include/c++/4.6 /usr/include/c++/4.6/i686-linux-gnu /usr/include/c++/4.6/backward忽略重复目录“/usr/include/c++/4.6/backward”忽略重复目录“/usr/include/c++/4.6”忽略重复目录“/usr/include/c++/4.6/backward”忽略重复目录“/usr/ include/c++/4.6" 忽略重复目录 "/usr/include/c++/4.6/i686-linux-gnu" 忽略重复目录 "/usr/include/c++/4.6/backward" 忽略重复目录"/usr/local/include " 忽略重复目录 "/usr/bin/../lib/clang/3.0/include" 忽略重复目录 "/usr/include" include "..." 搜索从这里开始: include <...> 搜索从这里开始: /usr/include/c++/4.6 /usr/include/c++/4.6/i686-linux-gnu /usr/include/c++/4.6/backward忽略重复目录“/usr/include/c++/4.6/backward”忽略重复目录“/usr/include/c++/4.6”忽略重复目录“/usr/include/c++/4.6/backward”忽略重复目录“/usr/ include/c++/4.6" 忽略重复目录 "/usr/include/c++/4.6/i686-linux-gnu" 忽略重复目录 "/usr/include/c++/4.6/backward" 忽略重复目录"/usr/local/include " 忽略重复目录 "/usr/bin/../lib/clang/3.0/include" 忽略重复目录 "/usr/include" include "..." 搜索从这里开始: include <...> 搜索从这里开始: /usr/include/c++/4.6 /usr/include/c++/4.6/i686-linux-gnu /usr/include/c++/4.6/backward忽略重复目录“/usr/include/c++/4.6” 忽略重复目录“/usr/include/c++/4.6/backward” 忽略重复目录“/usr/include/c++/4.6” 忽略重复目录“/usr/include/ c++/4.6/i686-linux-gnu"忽略重复目录"/usr/include/c++/4.6/backward"忽略重复目录"/usr/local/include"忽略重复目录"/usr/bin/../lib/ clang/3.0/include" 忽略重复目录 "/usr/include" 包含 "..." 搜索从这里开始:include <...> 搜索从这里开始:/usr/include/c++/4.6 /usr/include/c++/ 4.6/i686-linux-gnu /usr/include/c++/4.6/backward忽略重复目录“/usr/include/c++/4.6” 忽略重复目录“/usr/include/c++/4.6/backward” 忽略重复目录“/usr/include/c++/4.6” 忽略重复目录“/usr/include/ c++/4.6/i686-linux-gnu"忽略重复目录"/usr/include/c++/4.6/backward"忽略重复目录"/usr/local/include"忽略重复目录"/usr/bin/../lib/ clang/3.0/include" 忽略重复目录 "/usr/include" 包含 "..." 搜索从这里开始:include <...> 搜索从这里开始:/usr/include/c++/4.6 /usr/include/c++/ 4.6/i686-linux-gnu /usr/include/c++/4.6/backward忽略重复目录“/usr/include/c++/4.6”忽略重复目录“/usr/include/c++/4.6/i686-linux-gnu”忽略重复目录“/usr/include/c++/4.6/backward”忽略重复目录"/usr/local/include" 忽略重复目录 "/usr/bin/../lib/clang/3.0/include" 忽略重复目录 "/usr/include" include "..." 搜索从这里开始:include <. ..> 搜索从这里开始:/usr/include/c++/4.6 /usr/include/c++/4.6/i686-linux-gnu /usr/include/c++/4.6/backward忽略重复目录“/usr/include/c++/4.6”忽略重复目录“/usr/include/c++/4.6/i686-linux-gnu”忽略重复目录“/usr/include/c++/4.6/backward”忽略重复目录"/usr/local/include" 忽略重复目录 "/usr/bin/../lib/clang/3.0/include" 忽略重复目录 "/usr/include" include "..." 搜索从这里开始:include <. ..> 搜索从这里开始:/usr/include/c++/4.6 /usr/include/c++/4.6/i686-linux-gnu /usr/include/c++/4.6/backward忽略重复目录“/usr/bin/../lib/clang/3.0/include” 忽略重复目录“/usr/include” 包括“...” 从这里开始搜索:include <...> 从这里开始搜索:/ usr/include/c++/4.6 /usr/include/c++/4.6/i686-linux-gnu /usr/include/c++/4.6/backward忽略重复目录“/usr/bin/../lib/clang/3.0/include” 忽略重复目录“/usr/include” 包括“...” 从这里开始搜索:include <...> 从这里开始搜索:/ usr/include/c++/4.6 /usr/include/c++/4.6/i686-linux-gnu /usr/include/c++/4.6/backward
/usr/local/include /usr/bin/../lib/clang/3.0/include /usr/include
/usr/include/i386-linux-gnu/ /usr/include/clang/3.0/include/ /usr/ lib/gcc/i686-linux-gnu/4.6/include/
/usr/lib/gcc/i686-linux-gnu/4.6/include-fixed/ 搜索列表结束。
"/usr/bin/ld" -z relro --hash-style=gnu --as-needed --build-id --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so .2 -o a.out /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o /usr/lib/gcc/i686-linux -gnu/4.6/../../../i386-linux-gnu/crti.o /usr/lib/gcc/i686-linux-gnu/4.6/crtbegin.o -L/usr/lib/gcc/ i686-linux-gnu/4.6 -L/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu -L/lib/i386-linux-gnu -L /usr/lib/i386-linux-gnu -L/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu -L/usr/lib/gcc/ i686-linux-gnu/4.6/../../.. -L/lib/i386-linux-gnu -L/lib -L/usr/lib/i386-linux-gnu -L/usr/lib /tmp /teststring-e3FNx4.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i686-linux -gnu/4.6/crtend.o /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crtn.o
/tmp/teststring-e3FNx4.o:在函数std::basic_string、std::allocatormain':
teststring.cpp:(.text+0x18): undefined reference to

::basic_string()' teststring.cpp:(.text+0x2b): 未定义引用std::string::operator+=(char const*)' teststring.cpp:(.text+0x3e): undefined reference tostd::basic_string, std::allocator >::~basic_string()' teststring.cpp:(.text+0x58): 未定义引用to std::basic_string<char, std::char_traits<char>, std::allocator<char> ::~basic_string()' teststring.cpp:(.text+0x79): undefined reference tostd::terminate()' /tmp/teststring-e3FNx4.o:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0' clang: error: linker command failed with exit code 1 (use -v to see invocation)

好奇程序的 PS 是:

#include <string>
int main()
{
        std::string s;
        s+="banana";
}
4

1 回答 1

8

这是 C++ 代码,因此请尝试使用clang++而不是clang链接 C++ 标准库。

于 2013-02-25T11:49:38.780 回答