我试图通过两种方式从主干(~3.7)构建clang++
:通过gcc
(4.8)和通过(旧)clang++
(3.4和3.5)来自包经理)。它们都包含相同的步骤:
export CC=clang
export CXX=clang++
export CPLUS_INCLUDE_PATH="$CPLUS_INCLUDE_PATH:$HOME/llvm/projects/libcxxabi/include"
sudo apt-get install git
cd
git clone --single-branch --branch master --depth=1 http://llvm.org/git/llvm
cd llvm/projects/
git clone --single-branch --branch master --depth=1 http://llvm.org/git/libcxxabi
git clone --single-branch --branch master --depth=1 http://llvm.org/git/libcxx
git clone --single-branch --branch master --depth=1 http://llvm.org/git/compiler-rt
cd ../tools
git clone --single-branch --branch master --depth=1 http://llvm.org/git/clang
git clone --single-branch --branch master --depth=1 http://llvm.org/git/clang-tools-extra extra
git clone --single-branch --branch master --depth=1 http://llvm.org/git/lld
git clone --single-branch --branch master --depth=1 http://llvm.org/git/lldb
git clone --single-branch --branch master --depth=1 http://llvm.org/git/polly
sudo apt-get install python-dev libedit-dev libncurses-dev swig libgmp-dev libgmp3-dev dh-autoreconf libunwind8 libunwind8-dev cmake
cd
cd llvm/tools/polly/utils
mkdir -p ~/build-cloog
bash checkout_cloog.sh ~/build-cloog
mkdir -p ~/build-isl
bash checkout_isl.sh ~/build-isl
cd ~/build-isl/
./configure
make
sudo make install
cd ~/build-cloog/
./configure --with-isl=system
make
sudo make install
cd
mkdir build-llvm
cd build-llvm
bash ../llvm/configure --enable-optimized --disable-assertions --enable-libcpp --enable-jit --enable-targets=x86,x86_64 --enable-polly --enable-cxx1y --with-gmp=/usr/local --with-isl=/usr/local --with-cloog=/usr/local --with-binutils-include=/usr/include
make -j`nproc`
sudo make install
对于CC=clang
和CXX=clang++
,在链接包含std::istringstream
实例化的简单示例时出错:
#include <sstream>
#include <cstdlib>
int
main()
{
std::istringstream iss("1.1");
double x;
iss >> x;
return EXIT_SUCCESS;
}
错误:
user@ubuntu:~$ clang++ -stdlib=libc++ -std=gnu++1z -Ofast -march=native test.cpp -o /tmp/test
/tmp/test-785a74.o: In function `std::__1::basic_istringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_istringstream()':
test.cpp:(.text._ZNSt3__119basic_istringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEED0Ev[_ZNSt3__119basic_istringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEED0Ev]+0x5b): undefined reference to `operator delete(void*, unsigned long)'
/tmp/test-785a74.o: In function `virtual thunk to std::__1::basic_istringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_istringstream()':
test.cpp:(.text._ZTv0_n24_NSt3__119basic_istringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEED0Ev[_ZTv0_n24_NSt3__119basic_istringstreamIcNS_11char_traitsIcEENS_9allocatorIcEEED0Ev]+0x69): undefined reference to `operator delete(void*, unsigned long)'
/tmp/test-785a74.o: In function `std::__1::basic_stringbuf<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_stringbuf()':
test.cpp:(.text._ZNSt3__115basic_stringbufIcNS_11char_traitsIcEENS_9allocatorIcEEED0Ev[_ZNSt3__115basic_stringbufIcNS_11char_traitsIcEENS_9allocatorIcEEED0Ev]+0x26): undefined reference to `operator delete(void*, unsigned long)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
但是,如果CC=gcc
和CXX=g++
,则不会发生错误。在两种情况下,链接都是ld
{/ 1}}。
来自GNU Binutils
的对象的示例,没有这样的问题。
错误的原因是什么?我可以在不重建整个#include <iostream>
项目树的情况下修复它吗?
答案 0 :(得分:7)
铿锵干线最近发生了变化。编译器不再发出大小为operator delete的弱定义(请参阅commit 229241)。无论如何(-fdef-sized-delete
)发出定义的标志稍后在commit 229597中重命名。
您必须使用-fdefine-sized-deallocation
标志编译程序,以便clang发出大小的运算符delete。这应该可以解决您的链接错误。