我已经安装了 clang3.6,它运行良好,但当我尝试添加替代方案时
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang++-3.6 10
并在编译时使用它我得到以下错误
~PATH » dpkg -l | grep clang
ii clang-3.6 1:3.6-2ubuntu1~trusty1 amd64 C, C++ and Objective-C compiler (LLVM based)
ii clang-format-3.6 1:3.6-2ubuntu1~trusty1 amd64 Tool to format C/C++/Obj-C code
ii libclang-3.6-dev 1:3.6-2ubuntu1~trusty1 amd64 clang library - Development package
ii libclang-common-3.6-dev 1:3.6-2ubuntu1~trusty1 amd64 clang library - Common development package
ii libclang1-3.6:amd64 1:3.6-2ubuntu1~trusty1 amd64 C interface to the clang library
------------------------------------------------------------
~PATH » sudo update-alternatives --list clang
/usr/bin/clang++-3.6
------------------------------------------------------------
~PATH » clang++-3.6 -g -Wall -fsanitize=address --std=c++11 main.cpp
------------------------------------------------------------
~PATH » clang -g -Wall -fsanitize=address --std=c++11 main.cpp
/tmp/main-cb626d.o: In function `main':
PATH/main.cpp:5: undefined reference to `std::cin'
PATH/main.cpp:7: undefined reference to `std::istream::operator>>(int&)'
PATH/main.cpp:7: undefined reference to `std::istream::operator>>(int&)'
PATH/main.cpp:15: undefined reference to `std::cin'
PATH/main.cpp:15: undefined reference to `std::istream::operator>>(int&)'
PATH/main.cpp:15: undefined reference to `std::istream::operator>>(int&)'
/tmp/main-cb626d.o: In function `__cxx_global_var_init':
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/iostream:74: undefined reference to `std::ios_base::Init::Init()'
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
/tmp/main-cb626d.o: In function `std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::reserve(unsigned long)':
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/bits/vector.tcc:69: undefined reference to `std::__throw_length_error(char const*)'
/tmp/main-cb626d.o: In function `void std::vector<int, std::allocator<int> >::_M_emplace_back_aux<int const&>(int const&)':
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/bits/vector.tcc:426: undefined reference to `__cxa_begin_catch'
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/bits/vector.tcc:444: undefined reference to `__cxa_end_catch'
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/bits/vector.tcc:434: undefined reference to `__cxa_rethrow'
/tmp/main-cb626d.o: In function `std::vector<int, std::allocator<int> >::_M_check_len(unsigned long, char const*) const':
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/bits/stl_vector.h:1425: undefined reference to `std::__throw_length_error(char const*)'
/tmp/main-cb626d.o: In function `__clang_call_terminate':
main.cpp:(.text.__clang_call_terminate[__clang_call_terminate]+0x9): undefined reference to `__cxa_begin_catch'
main.cpp:(.text.__clang_call_terminate[__clang_call_terminate]+0x12): undefined reference to `std::terminate()'
/tmp/main-cb626d.o: In function `__gnu_cxx::new_allocator<int>::deallocate(int*, unsigned long)':
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/ext/new_allocator.h:110: undefined reference to `operator delete(void*)'
/tmp/main-cb626d.o: In function `__gnu_cxx::new_allocator<int>::allocate(unsigned long, void const*)':
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/ext/new_allocator.h:102: undefined reference to `std::__throw_bad_alloc()'
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/ext/new_allocator.h:104: undefined reference to `operator new(unsigned long)'
/tmp/main-cb626d.o: In function `std::vector<int, std::allocator<int> >* std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >::_M_allocate_and_copy<std::move_iterator<std::vector<int, std::allocator<int> >*> >(unsigned long, std::move_iterator<std::vector<int, std::allocator<int> >*>, std::move_iterator<std::vector<int, std::allocator<int> >*>)':
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/bits/stl_vector.h:1230: undefined reference to `__cxa_begin_catch'
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/bits/stl_vector.h:1234: undefined reference to `__cxa_rethrow'
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/bits/stl_vector.h:1236: undefined reference to `__cxa_end_catch'
/tmp/main-cb626d.o: In function `__gnu_cxx::new_allocator<std::vector<int, std::allocator<int> > >::deallocate(std::vector<int, std::allocator<int> >*, unsigned long)':
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/ext/new_allocator.h:110: undefined reference to `operator delete(void*)'
/tmp/main-cb626d.o: In function `std::vector<int, std::allocator<int> >* std::__uninitialized_copy<false>::__uninit_copy<std::move_iterator<std::vector<int, std::allocator<int> >*>, std::vector<int, std::allocator<int> >*>(std::move_iterator<std::vector<int, std::allocator<int> >*>, std::move_iterator<std::vector<int, std::allocator<int> >*>, std::vector<int, std::allocator<int> >*)':
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/bits/stl_uninitialized.h:77: undefined reference to `__cxa_begin_catch'
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/bits/stl_uninitialized.h:81: undefined reference to `__cxa_rethrow'
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/bits/stl_uninitialized.h:83: undefined reference to `__cxa_end_catch'
/tmp/main-cb626d.o: In function `__gnu_cxx::new_allocator<std::vector<int, std::allocator<int> > >::allocate(unsigned long, void const*)':
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/ext/new_allocator.h:102: undefined reference to `std::__throw_bad_alloc()'
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.3.0/../../../../include/c++/5.3.0/ext/new_allocator.h:104: undefined reference to `operator new(unsigned long)'
/tmp/main-cb626d.o:(.eh_frame+0x47): undefined reference to `__gxx_personality_v0'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
------------------------------------------------------------
~PATH » ll /usr/bin/clang /usr/bin/clang++-3.6
lrwxrwxrwx 1 root root 23 Mar 21 21:07 /usr/bin/clang -> /etc/alternatives/clang
lrwxrwxrwx 1 root root 27 Apr 28 2015 /usr/bin/clang++-3.6 -> ../lib/llvm-3.6/bin/clang++
------------------------------------------------------------
~PATH » ll /etc/alternatives/clang
lrwxrwxrwx 1 root root 20 Mar 21 21:14 /etc/alternatives/clang -> /usr/bin/clang++-3.6
答案1
你的来电...
clang -g -Wall -fsanitize=address --std=c++11 main.cpp
...最可能的意思是:“编译这个 C++ 源文件但链接一个 C 程序,而不是 C++”。
这导致缺少必要的 C++ 支持库。
令人惊讶的是,当我添加一个 clang++ 替代方案时,它工作了 o.0 –
确实,这意味着:编译此 C++ 代码并带来 C++ 程序所需的所有东西。现在还令人惊讶吗?