[cfe-dev] [LLVMdev] Building clang + libc++ + libc++abi

don hinton hintonda at gmail.com
Wed Jul 8 04:49:01 PDT 2015


If your cut-n-paste is accurate, you seem to be missing a closing quote for
CMAKE_CXX_LINK_FLAGS.

hth...
don
On Jul 8, 2015 2:22 AM, "David A. Greene" <greened at obbligato.org> wrote:

> greened at obbligato.org (David A. Greene) writes:
>
> > I looked at the instructions on the libc++ page and for Linux it
> > recommends building with -stdlib=libc++ -lc++abi.
> >
> > Encouraging!  Now, how do I get those options to a CMake build of
> > llvm/clang?  There's CMAKE_CXX_FLAGS but I'm not sure how to set it.
> > Will a simple -DCMAKE_CXX_FLAGS=-stdlib=libc++ suffice?  Will that
> > properly propagate from the command line without overriding all the
> > flags set by individual CMakeLists.txt files?  I don't want to, for
> > example, lose optimization flags on a release build.
> >
> > And what about linker flags?  What CMake variable controls those?  The
> > Google tells me nothing.
>
> I discovered CMAKE_CXX_LINK_FLAGS.  So I'm configuring like this:
>
> cmake -G "Unix Makefiles" -DCMAKE_C_COMPILER=clang
> -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS="-stdlib=libc++"
> -DCMAKE_CXX_LINK_FLAGS="-stdlib=libc++ -lc++abi
> -DPYTHON_EXECUTABLE=/opt/python/2.7.9/bin/python2.7
> -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/opt/clang/dev
> -DLLVM_APPEND_VC_REV=ON -DLLVM_ENABLE_CXX1Y=ON -DLLVM_ENABLE_ASSERTIONS=ON
> -DLLVM_PARALLEL_COMPILE_JOBS=32 -DLLVM_PARALLEL_LINK_JOBS=32
> -DLLVM_BUILD_DOCS=ON -DCLANG_INCLUDE_DOCS=ON -DLIBCXX_CXX_ABI=libcxxabi
> -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/path/to/llvm/projects/libcxxabi/include"
> /path/to/llvm
>
> This gets me a bit further but I am stuck here:
>
> Linking CXX shared library ../../../../lib/libclang.so
> cd /ptmp/dag/build/clang/tools/clang/tools/libclang &&
> /opt/cmake/3.0.1/bin/cmake -E cmake_link_script
> CMakeFiles/libclang.dir/link.txt --verbose=1
> /cray/css/compiler/cost/tools/x86_64-unknown-linux-gnu/clang/dev/bin/clang++
> -fPIC -stdlib=libc++ -fPIC -fvisibility-inlines-hidden -Wall -W
> -Wno-unused-parameter -Wwrite-strings -Wcast-qual
> -Wmissing-field-initializers -pedantic -Wno-long-long
> -Wcovered-switch-default -Wnon-virtual-dtor -std=c++1y -ffunction-sections
> -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing
> -Wno-nested-anon-types -O3   -Wl,-O3 -Wl,--gc-sections
> -Wl,--version-script,/ptmp/dag/build/clang/tools/clang/tools/libclang/libclang.exports
>  -Wl,-z,defs -shared -Wl,-soname,libclang.so.3.7 -o
> ../../../../lib/libclang.so.3.7 CMakeFiles/libclang.dir/ARCMigrate.cpp.o
> CMakeFiles/libclang.dir/BuildSystem.cpp.o
> CMakeFiles/libclang.dir/CIndex.cpp.o
> CMakeFiles/libclang.dir/CIndexCXX.cpp.o
> CMakeFiles/libclang.dir/CIndexCodeCompletion.cpp.o
> CMakeFiles/libclang.dir/CIndexDiagnostic.cpp.o
> CMakeFiles/libclang.dir/CIndexHigh.cpp.o
> CMakeFiles/libclang.dir/CIndexInclusionStack.cpp.o CMakeFiles/libclang.!
>  dir/CIndexUSRs.cpp.o CMakeFiles/libclang.dir/CIndexer.cpp.o
> CMakeFiles/libclang.dir/CXComment.cpp.o
> CMakeFiles/libclang.dir/CXCursor.cpp.o
> CMakeFiles/libclang.dir/CXCompilationDatabase.cpp.o
> CMakeFiles/libclang.dir/CXLoadedDiagnostic.cpp.o
> CMakeFiles/libclang.dir/CXSourceLocation.cpp.o
> CMakeFiles/libclang.dir/CXStoredDiagnostic.cpp.o
> CMakeFiles/libclang.dir/CXString.cpp.o CMakeFiles/libclang.dir/CXType.cpp.o
> CMakeFiles/libclang.dir/IndexBody.cpp.o
> CMakeFiles/libclang.dir/IndexDecl.cpp.o
> CMakeFiles/libclang.dir/IndexTypeSourceInfo.cpp.o
> CMakeFiles/libclang.dir/Indexing.cpp.o
> CMakeFiles/libclang.dir/IndexingContext.cpp.o ../../../../lib/libclangAST.a
> ../../../../lib/libclangBasic.a ../../../../lib/libclangFrontend.a
> ../../../../lib/libclangIndex.a ../../../../lib/libclangLex.a
> ../../../../lib/libclangSema.a ../../../../lib/libclangTooling.a
> ../../../../lib/libclangARCMigrate.a -ldl ../../../../lib/libLLVMCore.a
> ../../../../lib/libLLVMSupport.a ../../../../lib/libclangFormat.a!
>   ../../../../lib/libclangToolingCore.a
> ../../../../lib/libclangASTMatchers.a ../../../../lib/libclangFrontend.a
> ../../../../lib/libclangDriver.a ../../../../lib/libclangParse.a
> ../../../../lib/libLLVMMCParser.a ../../../../lib/libLLVMOption.a
> ../../../../lib/libclangSerialization.a ../../../../lib/libclangSema.a
> ../../../../lib/libclangEdit.a ../../../../lib/libLLVMBitReader.a
> ../../../../lib/libclangStaticAnalyzerCheckers.a
> ../../../../lib/libclangStaticAnalyzerCore.a
> ../../../../lib/libclangRewrite.a ../../../../lib/libclangAnalysis.a
> ../../../../lib/libclangAST.a ../../../../lib/libclangLex.a
> ../../../../lib/libclangBasic.a ../../../../lib/libLLVMCore.a
> ../../../../lib/libLLVMMC.a ../../../../lib/libLLVMSupport.a -lrt -ldl
> -lncurses -lpthread -lz -lm -Wl,-rpath,"\$ORIGIN/../lib"
> ../../../../lib/libLLVMSupport.a(Debug.cpp.o): In function `llvm::dbgs()':
> /ptmp/dag/llvm/llvm-ecosystem/llvm/lib/Support/Debug.cpp:(.text._ZN4llvm4dbgsEv+0x1b):
> undefined reference to `__cxa_guard_acquire'
> /ptmp/dag/llvm/llvm-ecosystem/llvm/lib/Support/Debug.cpp:(.text._ZN4llvm4dbgsEv+0x11a):
> undefined reference to `__cxa_guard_release'
>
> And a bazillion other undefined references.
>
> Is the problem the lack of -lc++abi on the link line?  That command
> comes from CMakeFiles/libclang.dir/link.txt which I can view and has the
> command above in it.  However, I cannot for the life of me figure out
> how that gets generated.  So I don't even know what CMake command I need
> to influence to get the proper link flags added.
>
> I tried messing around the LIBCLANG_LINK_FLAGS (discovered in libclang's
> CMakeLists.txt) but it didn't do anyting.
>
> Has anyone built this way on Linux?  I found a couple of references
> online but they seem pretty out of date.
>
>                           -David
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150708/e9c7d609/attachment.html>


More information about the cfe-dev mailing list