[cfe-users] Cannot build libc++ with Clang?

Jeffrey Walton noloader at gmail.com
Sat Jan 10 13:29:54 PST 2015


I have a script to build LLVM, Compiler Front End (Clang), Compiler RT
and Extras. It has worked fine since the Clang 3.2 days or so.

After building and installing Clang 3.5, Clang is having trouble
finding headers and runtime libraries on OS X 10.9. Attempts to
compile/link fails when using a minimal command line. If I add headers
with -I, then links fail. So I have to add libraries with -L and -l.

So I'm trying to build libc++ in-tree. I downloaded
libcxx-3.5.0.src.tar.xz, unpacked to libcxx. It was then moved to
llvm/projects. The same was done for to libcxxabi-3.5.0.src.tar.xz. It
was unpacked to libcxxabi and moved to llvm/projects. The instructions
were provided at http://libcxx.llvm.org.

I then configure as normal with:

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

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

Finally, I build:

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

Unfortunately, no libc++.{a|so|dylib|etc}.

--enable-libcpp was needed to compile the LLVM gear for OS X 10.7 and
10.8. But removing it does not help on OS X 10.9 (I was taking a stab
in the dark).

What am I doing wrong?

Thanks in advance.


**********

Here's the full build recipe.

#! /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

# Compiler 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 $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



More information about the cfe-users mailing list