LLVM Build Difficulties

I hope this is the right list for such questions.... I've been trying to get LLVM compiled under Linux (Ubuntu 9.04, 64 bit) for the last couple of days.

It all ends with the error:

llvm[2]: Linking Release executable tblgen (without symbols)
/home/cjones/Desktop/Build/llvm/utils/TableGen/Release/AsmMatcherEmitter.o: In function `(anonymous namespace)::AsmMatcherInfo::BuildInfo(llvm::CodeGenTarget&)':
AsmMatcherEmitter.cpp:(.text+0xbbbb): undefined reference to `llvm::StringRef::find(llvm::StringRef const&) const'
/home/cjones/Desktop/Build/llvm/utils/TableGen/Release/TableGen.o: In function `llvm::cl::opt<ActionType, false, llvm::cl::parser<ActionType> >::handleOccurrence(unsigned int, llvm::StringRef, llvm::StringRef)':
TableGen.cpp:(.gnu.linkonce.t._ZN4llvm2cl3optI10ActionTypeLb0ENS0_6parserIS2_EEE16handleOccurrenceEjNS_9StringRefES6_+0x292): undefined reference to `llvm::cl::Option::error(llvm::Twine const&, llvm::StringRef)'
collect2: ld returned 1 exit status
make[2]: *** [/home/cjones/Desktop/Build/llvm/Release/bin/tblgen] Error 1
make[2]: Leaving directory `/home/cjones/Desktop/Build/llvm/utils/TableGen'
make[1]: *** [TableGen/.makeall] Error 2
make[1]: Leaving directory `/home/cjones/Desktop/Build/llvm/utils'
make: *** [all] Error 1

I've tried an array of different gcc versions, and quite a few different configure options, but to no avail. The complete gamut of options looks like this presently:

  CXXFLAGS="-fPIC" ./configure --enable-optimized --enable-assertions --disable-multilib

I've got the latest code from subversion. I have clang checked out into tools/clang.

Let me know what additional information I can provide....

Any help would be appreciated.

Thanks.

Hi Curtis,

I hope this is the right list for such questions.... I've been trying to get LLVM compiled under Linux (Ubuntu 9.04, 64 bit) for the last couple of days.

I can't reproduce this with ubuntu 9.10, 64 bit x86, gcc 4.4.1, using
your configure options. What version of gcc are you using?

    CXXFLAGS="-fPIC" ./configure --enable-optimized --enable-assertions --disable-multilib

Not sure why you are passing -fPIC like this? Anyway, on my system it
didn't hurt: everything built fine anyway.

Ciao,

Duncan.

Duncan,

Thanks for the reply. As is usually the case, I managed to figure out that problem shortly after sending the email. I finally stumbled across directions that used "cmake" instead of the usual configure/make, and it worked perfectly. However, I'm stuck again.

I've got llvm/clang built as well as llvm-gcc, and PATH is set up such that they're both "visible"; and I can only imagine that I've done something really bad. llvm is in the path that contains "Build/llvm-objcts" while llvm-gcc is in "Install/llvm-gcc-4.4.2". Maybe there's some "-L" that I need to specify?

I've written a very small main.c that uses blocks, and when I try to compile/link it, I get:

$ clang -fblocks -v -o a.out main.c
clang version 1.1 (http://llvm.org/svn/llvm-project/cfe/trunk )
Target: x86_64-unknown-linux-gnu
Thread model: posix
  "/home/cjones/Desktop/Build/llvm-objects/bin/clang-cc" -triple x86_64-unknown-linux-gnu -S -disable-free -main-file-name main.c --relocation-model static --disable-fp-elim --unwind-tables=1 --mcpu=x86-64 --fmath-errno=1 -v -fblocks -fdiagnostics-show-option -o /tmp/cc.s -x c main.c
clang-cc version 1.1 based upon llvm 2.7svn hosted on x86_64-unknown-linux-gnu
ignoring nonexistent directory "/System/Library/Frameworks"
ignoring nonexistent directory "/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
  /home/cjones/Desktop/Build/llvm-objects/lib/clang/1.1/include
  /usr/local/include
  /usr/include
End of search list.
  "/home/cjones/Desktop/Install/llvm-gcc-4.2/bin/gcc" -fblocks -v -c -m64 -o /tmp/cc.o -x assembler /tmp/cc.s
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../llvm-gcc-4.2/configure --prefix=/home/cjones/Desktop/Install/llvm-gcc-4.2 --with-gmp=/home/cjones/Desktop/Install --with-mpfr=/home/cjones/Desktop/Install --enable-languages=c,c++ --disable-multilib --disable-bootstrap
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5653)
  as --traditional-format -V -Qy --64 -o /tmp/cc.o /tmp/cc.s
GNU assembler version 2.19.1 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.19.1
  "/home/cjones/Desktop/Install/llvm-gcc-4.2/bin/gcc" -fblocks -v -m64 -o a.out /tmp/cc.o
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../llvm-gcc-4.2/configure --prefix=/home/cjones/Desktop/Install/llvm-gcc-4.2 --with-gmp=/home/cjones/Desktop/Install --with-mpfr=/home/cjones/Desktop/Install --enable-languages=c,c++ --disable-multilib --disable-bootstrap
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5653)
  /home/cjones/Desktop/Install/llvm-gcc-4.2/libexec/gcc/x86_64-unknown-linux-gnu/4.2.1/collect2 --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib/../lib64/crt1.o /usr/lib/../lib64/crti.o /home/cjones/Desktop/Install/llvm-gcc-4.2/lib/gcc/x86_64-unknown-linux-gnu/4.2.1/crtbegin.o -L/home/cjones/Desktop/Install/llvm-gcc-4.2/lib/gcc/x86_64-unknown-linux-gnu/4.2.1 -L/home/cjones/Desktop/Install/llvm-gcc-4.2/lib/gcc/x86_64-unknown-linux-gnu/4.2.1/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/home/cjones/Desktop/Install/llvm-gcc-4.2/lib/gcc/x86_64-unknown-linux-gnu/4.2.1/../../.. /tmp/cc.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /home/cjones/Desktop/Install/llvm-gcc-4.2/lib/gcc/x86_64-unknown-linux-gnu/4.2.1/crtend.o /usr/lib/../lib64/crtn.o
/tmp/cc.o:(.rodata+0x0): undefined reference to `_NSConcreteGlobalBlock'
collect2: ld returned 1 exit status
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Again, any help would be appreciated.

Thanks.

Curtis Jones <curtis.jones@gmail.com> writes:

Thanks for the reply. As is usually the case, I managed to figure out
that problem shortly after sending the email. I finally stumbled
across directions that used "cmake" instead of the usual configure/
make, and it worked perfectly. However, I'm stuck again.

I've got llvm/clang built as well as llvm-gcc,

Your llvm-gcc is not using llvm. Please see README.LLVM on gcc source
root directory.

This is how llvm-gcc -v looks when properly built:

oscar@qcore:~/dev/llvm$ gcc-bin/bin/llvm-gcc -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc/configure --disable-multilib --prefix=/home/oscar/dev/llvm/gccbuild/../gcc-bin --program-prefix=llvm- --enable-llvm=/home/oscar/lib/llvm64StaticRelease/ --enable-languages=c,c++
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5653) (LLVM build)

`--enable-llvm` is the key `configure` option for using LLVM with
llvm-gcc.

Apart from this, if you use cmake to build LLVM, you must pass the path
to the *install* directory of LLVM to --enable-llvm, this means that you
must execute `make install` on the directory where you built llvm. The
variable CMAKE_INSTALL_PREFIX may be interesting to you on this regard,
see the cmake docs.

That said, it is possible that the problem about the undefined reference
is not related to llvm-gcc.

[snip]

Óscar,

Thanks for the help. I think I'm closer now ... hopefully; although I'm still getting the same error. The "gcc -v" output looks very similar to yours now. Do you see any other obvious configuration issues? I don't know what to try next....

$ ~/Desktop/Build/JamCloud/JamCloudServer$ gcc -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../llvm-gcc-svn/configure --prefix=/home/cjones/Desktop/Install/llvm-gcc-svn --program-prefix=llvm- --enable-languages=c,c++ --disable-multilib --enable-llvm=/home/cjones/Desktop/Install/llvm

$ ~/Desktop/Install/llvm/bin/clang -fblocks -v -o a.out main.c
clang version 1.1 (http://llvm.org/svn/llvm-project/cfe/trunk )
Target: x86_64-unknown-linux-gnu
Thread model: posix
  "/home/cjones/Desktop/Install/llvm/bin/../libexec/clang-cc" -triple x86_64-unknown-linux-gnu -S -disable-free -main-file-name main.c --relocation-model static --disable-fp-elim --unwind-tables=1 --mcpu=x86-64 --fmath-errno=1 -v -fblocks -fdiagnostics-show-option -o /tmp/cc.s -x c main.c
clang-cc version 1.1 based upon llvm 2.7svn hosted on x86_64-unknown-linux-gnu
ignoring nonexistent directory "/System/Library/Frameworks"
ignoring nonexistent directory "/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
  /home/cjones/Desktop/Install/llvm/lib/clang/1.1/include
  /usr/local/include
  /usr/include
End of search list.
  "/home/cjones/Desktop/Install/llvm-gcc-svn/bin/gcc" -fblocks -v -c -m64 -o /tmp/cc.o -x assembler /tmp/cc.s
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../llvm-gcc-svn/configure --prefix=/home/cjones/Desktop/Install/llvm-gcc-svn --program-prefix=llvm- --enable-languages=c,c++ --disable-multilib --enable-llvm=/home/cjones/Desktop/Install/llvm
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5653) (LLVM build)
  as --traditional-format -V -Qy --64 -o /tmp/cc.o /tmp/cc.s
GNU assembler version 2.19.1 (x86_64-linux-gnu) using BFD version (GNU Binutils for Ubuntu) 2.19.1
  "/home/cjones/Desktop/Install/llvm-gcc-svn/bin/gcc" -fblocks -v -m64 -o a.out /tmp/cc.o
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ../llvm-gcc-svn/configure --prefix=/home/cjones/Desktop/Install/llvm-gcc-svn --program-prefix=llvm- --enable-languages=c,c++ --disable-multilib --enable-llvm=/home/cjones/Desktop/Install/llvm
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5653) (LLVM build)
  /home/cjones/Desktop/Install/llvm-gcc-svn/libexec/gcc/x86_64-unknown-linux-gnu/4.2.1/collect2 --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib/../lib64/crt1.o /usr/lib/../lib64/crti.o /home/cjones/Desktop/Install/llvm-gcc-svn/lib/gcc/x86_64-unknown-linux-gnu/4.2.1/crtbegin.o -L/home/cjones/Desktop/Install/llvm-gcc-svn/lib/gcc/x86_64-unknown-linux-gnu/4.2.1 -L/home/cjones/Desktop/Install/llvm-gcc-svn/lib/gcc/x86_64-unknown-linux-gnu/4.2.1/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/home/cjones/Desktop/Install/llvm-gcc-svn/lib/gcc/x86_64-unknown-linux-gnu/4.2.1/../../.. /tmp/cc.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /home/cjones/Desktop/Install/llvm-gcc-svn/lib/gcc/x86_64-unknown-linux-gnu/4.2.1/crtend.o /usr/lib/../lib64/crtn.o
/tmp/cc.o:(.rodata+0x0): undefined reference to `_NSConcreteGlobalBlock'
collect2: ld returned 1 exit status
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Curtis Jones <curtis.jones@gmail.com> writes:

Thanks for the help. I think I'm closer now ... hopefully; although
I'm still getting the same error. The "gcc -v" output looks very
similar to yours now. Do you see any other obvious configuration
issues? I don't know what to try next....

[snip]

/tmp/cc.o:(.rodata+0x0): undefined reference to `_NSConcreteGlobalBlock'
collect2: ld returned 1 exit status
clang: error: linker command failed with exit code 1 (use -v to see
invocation)

Sorry, I know nothing about clang. My first guess is that you are
missing a library on the command line. Is NSConcreteGlobalBlock defined
in a library or in something that clang automatically links? If you are
proficient with `nm' you can try searching where NSConcreteGlobalBlock
is defined.

I would ask on the clang mailing list too.

You need -lBlocksRuntime on your link line. For more information, see <http://lists.cs.uiuc.edu/pipermail/llvmdev/2009-September/025954.html >

Shantonu

You need -lBlocksRuntime on your link line. For more information, see <http://lists.cs.uiuc.edu/pipermail/llvmdev/2009-September/025954.html

Thank you! That did it.

I had been copying the arguments that Xcode used and had forgotten that it was included in libSystem, which obviously doesn't help me on Linux.

Thanks again.