我熟悉clang,这就是当我尝试编译简单的2行程序时会发生的事情: (我在机器上有g ++,IDK,如果这是问题的原因)
clang teststring.cpp -v Ubuntu clang version 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 - 基于llvm 3.0的cc1 3.0版,托管在i386-pc-linux-gnu上 忽略不存在的目录“/ 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 /包括” 包含“...”搜索从这里开始: 包括< ...>搜索从这里开始:/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:在函数main':
std :: basic_string中,std :: allocator
teststring.cpp:(.text+0x18): undefined reference to:: basic_string()'teststring.cpp :(。text + 0x2b):未定义引用
std::string::operator+=(char const*)' teststring.cpp:(.text+0x3e): undefined reference to
std :: basic_string,std :: allocator&gt; :: ~basic_string()' teststring.cpp :(。text + 0x58):未定义的引用std::basic_string<char, std::char_traits<char>, std::allocator<char> ::~basic_string()' teststring.cpp:(.text+0x79): undefined reference to
std :: terminate()'/ tmp /teststring-e3FNx4.o :(.eh_frame+0x13): 未定义的引用`__gxx_personality_v0'clang:错误:链接器 命令失败,退出代码为1(使用-v查看调用)
P.S。对于好奇的节目是:
#include <string>
int main()
{
std::string s;
s+="banana";
}
答案 0 :(得分:8)
这是C ++代码,因此请尝试使用clang++
代替clang
,以便链接C ++标准库。