Failed to build clang from source

Asked 2 years ago, Updated 2 years ago, 97 views

Attempting to build clang in Ubuntu 19.04 environment fails.
Why?
I am trying to build the C/C++ toolchain from 1.
glibc, libc++, libc++abi, llvm seem to have been able to build.

I'm trying to build it by running cmake as follows, but it doesn't work and I get an error similar to the one below.

The undefined reference llvm::cl::ParseCommandLineOptions(int,char const*const*,llvm::StringRef,llvm::raw_ostream*,char const*) is also an error in /home/yuya/opt/lib/libLLVMSupport.a/cmLAake.
Why?

/home/username/opt is the directory specified in INSTALL_PREFIX, where glibc, libc++abi, libc++, llvm are installed.

additional:

I think it's wrong to pass CMAKE_CXX(C)_FLAGS -L to indicate the location of the library and -l to indicate the name of the library. How do I pass CMAKE to the compiler?

Additional 2:

It seems wrong to pass the library location and name to CMAKE_CXX(C)_FLAGS.
It seems that it is correct to give it to DCMAKE_SHARED_LINKER_FLAGS.
I tried cmake2, but the error still occurs.

Error:

/usr/bin/ld:CMakeFiles/obj.clang-tblgen.dir/TableGen.cpp.o:in function `main':
/home/username/src/llvm-project/clang/utils/TableGen/TableGen.cpp:306: undefined reference to `llvm::cl::ParseCommandLineOptions(int,char const*const*,llvm:::StringRef,llvm:::raw_ostream,*)
collect2:error:ld returned1 exit status

cmake:

cmake-G "Unix Makefiles"\
    - DCMAKE_BUILD_TYPE = RelWithDebInfo\
    - DCMAKE_INSTALL_PREFIX="/home/username/clang_test_opt"\
    -DCMAKE_C_FLAGS="-I/home/username/opt/include\
    - I/home/username/src/llvm-project/include\
    - I/home/username/src/llvm-project/llvm/include\
    -L/home/username/opt/lib\
    -lLLVMSupport"\
    -DCMAKE_CXX_FLAGS="-I/home/username/opt/include\
        - I/home/username/src/llvm-project/clang/include\
        - I/home/username/src/llvm-project/llvm/include\
        -L/home/username/opt/lib\
        -lLLVMSupport"\
    -DLLVM_TABLEGEN_EXE="/home/username/opt/bin/llvm-tblgen"\
    -DLLVM_LIBRARY_DIR="/home/username/llvm-project/llvm/lib"\
    -DLLVM_TOOLS_BINARY_DIR="/home/username/opt/bin"\
    -DLLVM_MAIN_INCLUDE_DIR="/home/username/src/llvm-project/llvm/include"\
    - DLLVM_DIR="/home/username/src/llvm-project/llvm/cmake"\
    .../llvm-project/clang

cmake2:

cmake-G "Unix Makefiles"\
    - DCMAKE_BUILD_TYPE = RelWithDebInfo\
    - DCMAKE_INSTALL_PREFIX=/home/username/clang_test_opt\
    -DCMAKE_C_FLAGS="-I/home/username/opt/include\
        - I/home/username/src/llvm-project/include\
        - I/home/username/src/llvm-project/llvm/include"\
    -DCMAKE_CXX_FLAGS="-I/home/username/opt/include\
        - I/home/username/src/llvm-project/clang/include\
        - I/home/username/src/llvm-project/llvm/include"\
    -DCMAKE_SHARED_LINKER_FLAGS="-L/home/username/opt/lib\
        -lLLVMSupport"\
    -DLLVM_TABLEGEN_EXE=/home/username/opt/bin/llvm-tblgen\
    -DLLVM_LIBRARY_DIR=/home/username/llvm-project/llvm/lib\
    -DLLVM_TOOLS_BINARY_DIR=/home/username/opt/bin\
    -DLLVM_MAIN_INCLUDE_DIR=/home/username/src/llvm-project/llvm/include\
    - DLLVM_DIR=/home/username/src/llvm-project/llvm/cmake\
    -DZ3_LIBRARIES=/home/username/opt/lib\
    -DZ3_INCLUDE_DIR=/home/username/opt/include\
    .../llvm-project/clang

c++ build cmake llvm

2022-09-30 21:43

1 Answers

It does not answer the direct question of the person who asked the question, but
Failed to build from source.It took a little over 10 hours in this environment.

[clang]

10.0.0 (trunc372494)

[Build source]

 svnco http://llvm.org/svn/llvm-project/llvm/trunk llvm
svnco http://llvm.org/svn/llvm-project/cfe/trunk clang
svnco http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra
svnco http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt

[Build Environment]

  • WSL
  • Ubuntu 18.04.3 LTS (Bionic Beaver)
  • cmake 3.10.2
  • gcc7.4.0
  • ld2.30
  • make 4.1
  • python 2.7.15+

[Reference Page]

[November 2018] Compile/build compiler-based LLVM+Clang from scratch (AWS+CentOS7). -Qiita

Replace the procedure because the environment is different (*) It is necessary, but it was almost unmodified and the build went well.(*Use apt instead of yum)


2022-09-30 21:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.