gpt4 book ai didi

c++ - clang 无法链接 2 行主函数程序

转载 作者:太空狗 更新时间:2023-10-29 20:05:09 26 4
gpt4 key购买 nike

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

clang teststring.cpp -v Ubuntu clang version 3.0-6ubuntu3 (tags/RELEASE_30/final) (based on LLVM 3.0) Target: i386-pc-linux-gnu Thread model: 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 version 3.0 based upon llvm 3.0 hosted on i386-pc-linux-gnu ignoring nonexistent directory "/usr/include/i686-linux-gnu" ignoring nonexistent directory "/usr/include/c++/4.6//i686-linux-gnu/32" ignoring nonexistent directory "/usr/include/i686-linux-gnu/" ignoring nonexistent directory "/usr/include/i686-linux-gnu" ignoring duplicate directory "/usr/include/c++/4.6" ignoring duplicate directory "/usr/include/c++/4.6/i686-linux-gnu" ignoring duplicate directory "/usr/include/c++/4.6/backward" ignoring duplicate directory "/usr/include/c++/4.6" ignoring duplicate directory "/usr/include/c++/4.6/backward" ignoring duplicate directory "/usr/include/c++/4.6" ignoring duplicate directory "/usr/include/c++/4.6/i686-linux-gnu" ignoring duplicate directory "/usr/include/c++/4.6/backward" ignoring duplicate directory "/usr/local/include" ignoring duplicate directory "/usr/bin/../lib/clang/3.0/include" ignoring duplicate directory "/usr/include" include "..." search starts here: include <...> search starts here: /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/ End of search list.
"/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: In function main':<br/>
teststring.cpp:(.text+0x18): undefined reference to
std::basic_string, std::allocator

::basic_string()' teststring.cpp:(.text+0x2b): undefined reference to std::string::operator+=(char const*)' teststring.cpp:(.text+0x3e):
undefined reference to
std::basic_string, std::allocator >::~basic_string()' teststring.cpp:(.text+0x58): undefined reference to 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): undefined reference to `__gxx_personality_v0' clang: error: linker command failed with exit code 1 (use -v to see invocation)

附言好奇的程序是:

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

最佳答案

这是 C++ 代码,所以尝试使用 clang++ 而不是 clang 以便链接 C++ 标准库。

关于c++ - clang 无法链接 2 行主函数程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15066258/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com