[llvm-dev] Building LLVM with LLVM

1,006 views
Skip to first unread message

Fabiano Sidler via llvm-dev

unread,
Sep 5, 2019, 6:15:46 AM9/5/19
to llvm...@lists.llvm.org
Hi folks!

I'm trying to build LLVM with LLVM on Ubuntu using the commands below.
Building it with the GNU stuff (cpp, gcc, g++ and binutils packages) works,
but after removing it, moving LLVM to /usr/local and symlinking /usr/bin/ld
to ld.lld, I'm getting the following:
=== snip ===
-- The C compiler identification is Clang 8.0.1
-- The CXX compiler identification is Clang 8.0.1
-- The ASM compiler identification is Clang
-- Found assembler: /usr/local/bin/clang
-- Check for working C compiler: /usr/local/bin/clang
-- Check for working C compiler: /usr/local/bin/clang -- broken
CMake Error at /usr/share/cmake-3.5/Modules/CMakeTestCCompiler.cmake:61 (message):
The C compiler "/usr/local/bin/clang" is not able to compile a simple test
program.

It fails with the following output:

Change Dir: /home/elux/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_a9eab/fast"

/usr/bin/make -f CMakeFiles/cmTC_a9eab.dir/build.make
CMakeFiles/cmTC_a9eab.dir/build

make[1]: Entering directory '/home/elux/build/CMakeFiles/CMakeTmp'

Building C object CMakeFiles/cmTC_a9eab.dir/testCCompiler.c.o

/usr/local/bin/clang -o CMakeFiles/cmTC_a9eab.dir/testCCompiler.c.o -c
/home/elux/build/CMakeFiles/CMakeTmp/testCCompiler.c

Linking C executable cmTC_a9eab

/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_a9eab.dir/link.txt
--verbose=1

/usr/local/bin/clang CMakeFiles/cmTC_a9eab.dir/testCCompiler.c.o -o
cmTC_a9eab

ld: error: cannot open crt1.o: No such file or directory

ld: error: cannot open crti.o: No such file or directory

ld: error: cannot open crtbegin.o: No such file or directory

ld: error: unable to find library -lgcc

ld: error: unable to find library -lgcc_s

ld: error: unable to find library -lc

ld: error: unable to find library -lgcc

ld: error: unable to find library -lgcc_s

ld: error: cannot open crtend.o: No such file or directory

ld: error: cannot open crtn.o: No such file or directory

clang-8: error: linker command failed with exit code 1 (use -v to see
invocation)

CMakeFiles/cmTC_a9eab.dir/build.make:97: recipe for target 'cmTC_a9eab'
failed

make[1]: *** [cmTC_a9eab] Error 1

make[1]: Leaving directory '/home/elux/build/CMakeFiles/CMakeTmp'

Makefile:126: recipe for target 'cmTC_a9eab/fast' failed

make: *** [cmTC_a9eab/fast] Error 2

CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:39 (project)


-- Configuring incomplete, errors occurred!
See also "/home/elux/build/CMakeFiles/CMakeOutput.log".
See also "/home/elux/build/CMakeFiles/CMakeError.log".
=== snap ===

Commands used:
=== snip ===
VERSION=8.0.1
DESTDIR=/tmp/llvm
PREFIX=/usr/local

#wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${VERSION}/llvm-${VERSION}.src.tar.xz
#wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${VERSION}/cfe-${VERSION}.src.tar.xz
#wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${VERSION}/libcxx-${VERSION}.src.tar.xz
#wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${VERSION}/libcxxabi-${VERSION}.src.tar.xz
#wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${VERSION}/lld-${VERSION}.src.tar.xz
#wget https://github.com/llvm/llvm-project/releases/download/llvmorg-${VERSION}/compiler-rt-${VERSION}.src.tar.xz
tar xf llvm-${VERSION}.src.tar.xz
tar xf cfe-${VERSION}.src.tar.xz
tar xf libcxx-${VERSION}.src.tar.xz
tar xf libcxxabi-${VERSION}.src.tar.xz
tar xf lld-${VERSION}.src.tar.xz
tar xf compiler-rt-${VERSION}.src.tar.xz
mv cfe-${VERSION}.src llvm-${VERSION}.src/projects/clang
mv libcxx-${VERSION}.src llvm-${VERSION}.src/projects/libcxx
mv libcxxabi-${VERSION}.src llvm-${VERSION}.src/projects/libcxxabi
mv lld-${VERSION}.src llvm-${VERSION}.src/projects/lld
mv compiler-rt-${VERSION}.src llvm-${VERSION}.src/projects/compiler-rt
mkdir build
cd build
cmake \
-DLLVM_ENABLE_FFI=ON \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_RTTI=ON \
-DLLVM_TARGETS_TO_BUILD="host" \
-DBUILD_SHARED_LIBS=ON \
../llvm-${VERSION}.src
cmake --build .
cmake -DCMAKE_INSTALL_PREFIX=${DESTDIR}${PREFIX} -P cmake_install.cmake
=== snap ===

Any hints?

Greetings,
Fabiano
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

David Blaikie via llvm-dev

unread,
Sep 5, 2019, 3:27:13 PM9/5/19
to Fabiano Sidler, llvm...@lists.llvm.org
If you removed your entire GCC installation (including the runtime libraries and standard library), yeah, I'm not sure that'll work out of the box with Clang - clang does have implementations of some pieces (libc++, for instance - though clang doesn't default to using it (not sure if it'll use it in favor if libstdc++ is missing, or if it'll fail)) I'm not sure all the pieces are there. (I don't know the nuance of the various libgcc_s, compiler-rt, etc, etc)

Long story short - keep your GCC installation, install clang, use the CMAKE_C_COMPILER, CMAKE_CXX_COMPILER, etc, flags to specify that you want to use clang instead of gcc as your compiler.

Michael Spencer via llvm-dev

unread,
Sep 5, 2019, 8:57:04 PM9/5/19
to David Blaikie, llvm...@lists.llvm.org
On Thu, Sep 5, 2019 at 12:27 PM David Blaikie via llvm-dev <llvm...@lists.llvm.org> wrote:
If you removed your entire GCC installation (including the runtime libraries and standard library), yeah, I'm not sure that'll work out of the box with Clang - clang does have implementations of some pieces (libc++, for instance - though clang doesn't default to using it (not sure if it'll use it in favor if libstdc++ is missing, or if it'll fail)) I'm not sure all the pieces are there. (I don't know the nuance of the various libgcc_s, compiler-rt, etc, etc)

Specifically the llvm-project does not yet have a libc, so it doesn't provide crt1.o and friends.  To use clang without any gnu facilities you'll need a libc (musl is pretty good) and you'll need to change the driver to use compiler-rt.  I think you can look at the freebsd driver for a platform that uses as much llvm as possible.

- Michael Spencer

Fabiano Sidler via llvm-dev

unread,
Sep 10, 2019, 6:20:21 AM9/10/19
to llvm...@lists.llvm.org
Thus wrote Michael Spencer:

> Specifically the llvm-project does not yet have a libc, so it doesn't
> provide crt1.o and friends. To use clang without any gnu facilities you'll
> need a libc (musl is pretty good) and you'll need to change the driver to
> use compiler-rt. I think you can look at the freebsd driver for a platform
> that uses as much llvm as possible.

Thanks for the recommendation, but using the default system libc is fine for me.

Fabiano Sidler via llvm-dev

unread,
Sep 10, 2019, 10:16:03 AM9/10/19
to llvm...@lists.llvm.org
Thus wrote David Blaikie:

> If you removed your entire GCC installation (including the runtime
> libraries and standard library), yeah, I'm not sure that'll work out of the
> box with Clang - clang does have implementations of some pieces (libc++,
> for instance - though clang doesn't default to using it (not sure if it'll
> use it in favor if libstdc++ is missing, or if it'll fail)) I'm not sure
> all the pieces are there. (I don't know the nuance of the various libgcc_s,
> compiler-rt, etc, etc)

I'm at that point now. I'v successfully built LLVM9 (including compiler-rt
and libcxx{,abi}, but I still can't build LLVM9 without GNU's libstdc++
because configuring without it fails with:
ld: error: unable to find library -lstdc++
Anyone knows how to enforce the use of LLVM's libcxx?

Greetings

Fabiano Sidler via llvm-dev

unread,
Sep 10, 2019, 10:19:16 AM9/10/19
to llvm...@lists.llvm.org
Thus wrote Olivier Galibert:

> On Thu, Sep 5, 2019 at 12:15 PM Fabiano Sidler via llvm-dev <
> llvm...@lists.llvm.org> wrote:
>
> > ld: error: cannot open crt1.o: No such file or directory
> >
> [...]

>
> > ld: error: unable to find library -lgcc
> >
>
> clang/llvm 8, specifically compiler-rt, does not provide everything needed
> to replace the gcc-provided environment under linux. Clang 9 should,
> thought, given https://reviews.llvm.org/D28791 and some others.

Yes, could build LLVM9 with LLVM8 and without libgcc. Thanks for the hint!
Will track version 9 now.

David Blaikie via llvm-dev

unread,
Sep 10, 2019, 2:19:42 PM9/10/19
to Fabiano Sidler, llvm...@lists.llvm.org
you'd need to add -stdlib=libc++ to your C++ compiler flags, I believe
Reply all
Reply to author
Forward
0 new messages