其他分享
首页 > 其他分享> > 来自libc的istringstream的析构函数中对operator delete的未定义引用

来自libc的istringstream的析构函数中对operator delete的未定义引用

作者:互联网

我试图通过两种方式从trunk(~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,则不会发生错误.在两种情况下,链接器都来自GNU Binutils.

来自#include< iostream>的对象的示例没有这样的问题.

错误的原因是什么?我可以在不重建整个clang / llvm项目树的情况下修复它吗?

解决方法:

clang trunk最近发生了变化.编译器不再发出大小为operator delete的弱定义(参见commit 229241).无论如何发出定义的标志(-fdef-sized-delete)在commit 229597中稍后重命名.

您必须使用-fdefine-sized-deallocation标志编译程序,以便clang发出大小的运算符delete.这应该可以解决您的链接错误.

标签:c,clang,gcc,clang-2
来源: https://codeday.me/bug/20190728/1559751.html