Unknown package libcxx and libcxxabi when building Clang?

给你一囗甜甜゛ 提交于 2019-12-10 16:49:10

问题


I'm trying to build Clang with libc++ from sources. And I'm trying to drop libc++ in-tree while building it out-of-tree with the other components. The recipe I use is below.

If I simply place libcxx and libcxxabi in-tree, then configure does not pick them up, and they are not built automatically. I placed them in llvm/projects per LLVM's libc++ Standard Library.

Additionally, adding make cxx to the recipe does not work as advertised on the LLVM's libc++ Standard Library page. It results in:

llvm[0]: Constructing LLVMBuild project information.
make: *** No rule to make target `cxx'.  Stop.

When I configure LLVM/Clang with --with-libcxx and --with-libcxxabi:

# Issued from a scratch 'build' directory, which is next to the 'llvm' directory.
../llvm/configure --enable-optimized --enable-cxx11 --with-libcxx --with-libcxxabi \
    $OTHER_OPTIONS --prefix=/usr/local

then I receive the following:

configure: WARNING: Unknown project (libcxx) won't be configured automatically
configure: WARNING: Unknown project (libcxxabi) won't be configured automatically

libcxx and libcxxabi are literally what LLVM calls them, so I'm not sure what names to use if they are not correct.

I tried to examine configure for what the package names should be, but its not very helpful. See below for the logic.

How do I configure and build Clang with libc++ (when libc++ and libc++ ABI are in-tree)?


Configure logic for --with-XXX is shown below.

this is all I can find (its not very helpful):

  -with-* | --with-*)
    ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
    # Reject names that are not valid shell variable names.
    expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null &&
      { echo "$as_me: error: invalid package name: $ac_package" >&2
   { (exit 1); exit 1; }; }
    ac_package=`echo $ac_package| sed 's/-/_/g'`
    eval with_$ac_package=\$ac_optarg ;;

Related links:

  • LLVM/Clang download page
  • LLVM's libc++ Standard Library page

And this Stack Overflow question is related: When is libc++ sources needed when building Clang from sources?

And this discussion of CFE-Dev mailing list: Questions about libc++ for linux and its git repository (if any). The thread says unpacking libcxx into llcm/projects ensures the headers are copied where Clang expects them during make install. But it does not address the --with-XXX question, it does not discuss why libc++ was not built, and it does not discuss how to get make install to actually install the libraries.


Recipe to fetch and build Clang. It works fine when not including libcxx and libcxxabi.

#! /bin/sh

# Clang 3.5 recipe.
#   The script should be run from a scratch directory.

# Fetch

if [ ! -e llvm-3.5.0.src.tar.xz ]; then
  wget http://llvm.org/releases/3.5.0/llvm-3.5.0.src.tar.xz
fi

if [ ! -e cfe-3.5.0.src.tar.xz ]; then
  wget http://llvm.org/releases/3.5.0/cfe-3.5.0.src.tar.xz
fi

if [ ! -e compiler-rt-3.5.0.src.tar.xz ]; then
  wget http://llvm.org/releases/3.5.0/compiler-rt-3.5.0.src.tar.xz
fi

if [ ! -e libcxx-3.5.0.src.tar.xz ]; then
  wget http://llvm.org/releases/3.5.0/libcxx-3.5.0.src.tar.xz
fi

if [ ! -e libcxxabi-3.5.0.src.tar.xz ]; then
  wget http://llvm.org/releases/3.5.0/libcxxabi-3.5.0.src.tar.xz
fi

if [ ! -e clang-tools-extra-3.5.0.src.tar.xz ]; then
  wget http://llvm.org/releases/3.5.0/clang-tools-extra-3.5.0.src.tar.xz
fi

# Cleanup

echo "Cleaning up artifacts"
rm -rf llvm build llvm-3.5.0.src

# LLVM
echo "Unpacking LLVM"
tar xf llvm-3.5.0.src.tar.xz
mv llvm-3.5.0.src/ llvm

# Clang Front End
echo "Unpacking Clang Front End"
cd llvm/tools
tar xf ../../cfe-3.5.0.src.tar.xz
mv cfe-3.5.0.src clang
cd ../../

# Compiler RT
echo "Unpacking Compiler RT"
cd llvm/projects
tar xf ../../compiler-rt-3.5.0.src.tar.xz
mv compiler-rt-3.5.0.src/ compiler-rt
cd ../../

# Extra Tools
echo "Unpacking Extra Tools"
cd llvm/tools/clang/tools/
tar xf ../../../../clang-tools-extra-3.5.0.src.tar.xz
mv clang-tools-extra-3.5.0.src extra
cd ../../../../

# libc++
echo "Unpacking libc++"
cd llvm/projects
tar xf ../../libcxx-3.5.0.src.tar.xz
mv libcxx-3.5.0.src/ libcxx
cd ../../

# libc++ ABI
echo "Unpacking libc++ ABI"
cd llvm/projects
tar xf ../../libcxxabi-3.5.0.src.tar.xz
mv libcxxabi-3.5.0.src/ libcxxabi
cd ../../

# Determine if Apple
IS_DARWIN=`uname -s | egrep -i -c "Darwin"`
if [ $IS_DARWIN -ne 0 ]; then
  OTHER_OPTIONS=" --enable-libcpp"
fi

# Configure
echo "Configuring build"
mkdir -p build
cd build
../llvm/configure --enable-optimized --enable-cxx11 --with-libcxx --with-libcxxabi $OTHER_OPTIONS --prefix=/usr/local

# Build
# 'make cxx' for libc++ is from http://libcxx.llvm.org/
echo "Running make"
make cxx
make -j2

RET=$?
if [ $RET -eq 0 ];then
    echo "****************************************"
    read -p "Press [ENTER] to install, or [CTRL]+C to quit"
    sudo make install
fi

# ****************************************
# ****************************************

# Install does not install scan-build and scan-view
# Perform the copy, and/or put them on-path

#sudo cp llvm/projects/compiler-rt/lib/asan/scripts/asan_symbolize.py /usr/local/bin
#sudo 2to3 -w /usr/local/bin/asan_symbolize.py

#sudo mkdir /usr/local/bin/scan-build
#sudo cp -r llvm/tools/clang/tools/scan-build /usr/local/bin

#sudo mkdir /usr/local/bin/scan-view
#sudo cp -r llvm/tools/clang/tools/scan-view /usr/local/bin

回答1:


This is script which I used to build libcxxabi and libcxx. It use previously built Clang (with GCC (4.8.3 in my case) and GCC STL):

if ( $#argv != 2 ) then
    echo "Usage: [32|64] <directory>"
    exit
endif

set echo on

set CMake=<CMake executable>
set GCCDir=<recent GCC directory>
set LLVMSourceDir=${PWD}/llvm-${LLVM_VERSION}.src
set LLVMOutOfTreeSourceDir=${PWD}
set LLVMPass1Dir=${PWD}/pass1
set PythonDir=<Python directory>
set InstallDir=${PWD}/$argv[2]

if ( $argv[1] == 32 ) then
    set GCC_EHDir=${GCCDir}/lib/gcc/x86_64-redhat-linux/4.8.3/32
    set BuildMode="-m32"
    set LibDirSuffix=""
else
    set GCC_EHDir=${GCCDir}/lib/gcc/x86_64-redhat-linux/4.8.3
    set BuildMode="-m64"
    set LibDirSuffix="64"
endif

set BuildDir=libcxxabi.build

if ( -d ${BuildDir} ) then
    rm -rf ${BuildDir}
endif

mkdir ${BuildDir}
cd ${BuildDir}

${CMake}                                                \
    -DCMAKE_BUILD_TYPE="Release"                                    \
    -DCMAKE_INSTALL_PREFIX:PATH=${InstallDir}                           \
    -DCMAKE_C_COMPILER=${LLVMPass1Dir}/bin/clang                            \
    -DCMAKE_C_FLAGS=${BuildMode}                                    \
    -DCMAKE_CXX_COMPILER=${LLVMPass1Dir}/bin/clang++                        \
    -DCMAKE_CXX_FLAGS=${BuildMode}                                  \
    -DCMAKE_SHARED_LINKER_FLAGS="-L ${GCC_EHDir}"                           \
    -DCMAKE_STATIC_LINKER_FLAGS="${GCC_EHDir}/libgcc_eh.a"                      \
    -DLLVM_FORCE_USE_OLD_TOOLCHAIN=YES                              \
    -DLLVM_PATH=${LLVMSourceDir}                                    \
    -DLIBCXXABI_LIBCXX_INCLUDES=${LLVMOutOfTreeSourceDir}/libcxx-${LLVM_VERSION}.src/include    \
    -DLIBCXXABI_LIBCXX_PATH=${LLVMOutOfTreeSourceDir}/libcxx-${LLVM_VERSION}.src            \
    -DLIBCXXABI_LIBDIR_SUFFIX=${LibDirSuffix}                           \
    ${LLVMOutOfTreeSourceDir}/libcxxabi-${LLVM_VERSION}.src

make
make install

cd ..

set BuildDir=libcxx.build

if ( -d ${BuildDir} ) then
    rm -rf ${BuildDir}
endif

mkdir ${BuildDir}
cd ${BuildDir}

${CMake}                                                \
    -DCMAKE_BUILD_TYPE="Release"                                    \
    -DCMAKE_INSTALL_PREFIX:PATH=${InstallDir}                           \
    -DCMAKE_C_COMPILER=${LLVMPass1Dir}/bin/clang                            \
    -DCMAKE_C_FLAGS=${BuildMode}                                    \
    -DCMAKE_CXX_COMPILER=${LLVMPass1Dir}/bin/clang++                        \
    -DCMAKE_CXX_FLAGS=${BuildMode}                                  \
    -DCMAKE_SHARED_LINKER_FLAGS="-L ${GCCDir}/lib${LibDirSuffix}"                   \
    -DLLVM_PATH=${LLVMSourceDir}                                    \
    -DLIBCXX_CXX_ABI=libcxxabi                                  \
    -DLIBCXX_CXX_ABI_INCLUDE_PATHS=${LLVMOutOfTreeSourceDir}/libcxxabi-${LLVM_VERSION}.src/include  \
    -DLIBCXX_CXX_ABI_LIBRARY_PATH=${InstallDir}/lib                         \
    -DLIBCXX_LIBDIR_SUFFIX=${LibDirSuffix}                              \
    -DLIT_EXECUTABLE=${LLVMSourceDir}/utils/lit/lit.py                      \
    ${LLVMOutOfTreeSourceDir}/libcxx-${LLVM_VERSION}.src

make
make install

cd ..



回答2:


libc++ and libc++abi aren't maintained to work with configure. I think libc++ might work if you invoke it correctly, but there isn't even a configure script for libc++abi.

See our docs for using cmake with these projects:

# In-tree build:
# Check out libcxx and libcxxabi into llvm/projects
cd llvm
mkdir build && cd build
cmake .. # Linux may require -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++
make cxx


来源:https://stackoverflow.com/questions/27881949/unknown-package-libcxx-and-libcxxabi-when-building-clang

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!