Open ligurio opened 3 weeks ago
Like it says in #357, this is a packaging issue. If you follow the instructions in the README to build LLVM from source you will not see this.
I've followed instructions in a README.md and built LLVM 13 from source. Building terra with LLVM 13 produces a huge number of linkage errors:
<snipped>
[ 99%] Building CXX object src/CMakeFiles/TerraExecutable.dir/linenoise.cpp.o
[ 99%] Building CXX object src/CMakeFiles/TerraExecutable.dir/main.cpp.o
[100%] Linking CXX executable ../bin/terra
/bin/ld: ../lib/libterra_s.a(ASTUnit.cpp.o): in function `(anonymousnamespace)::ASTInfoCollector::ReadHeaderSearchOptions(clang::Header
SearchOptions const&, llvm::StringRef, bool)':
ASTUnit.cpp(.text._ZN12_GLOBAL__N_116ASTInfoCollector23ReadHeaderSearchOptionsERKN5clang19HeaderSearchOptionsEN4llvm9StringRefEb+0xdc4): undefined reference to `llvm::SmallVectorBase<unsigned int>::mallocForGrow(unsigned long, unsigned long, unsigned long&)'
/bin/ld: ../lib/libterra_s.a(ASTUnit.cpp.o): in function `llvm::SmallVectorTemplateBase<clang::FixItHint, false>::grow(unsigned long)':
ASTUnit.cpp:(.text._ZN4llvm23SmallVectorTemplateBaseIN5clang9FixItHintELb0EE4growEm[_ZN4llvm23SmallVectorTemplateBaseIN5clang9FixItHintE
Lb0EE4growEm]+0x2a): undefined reference to `llvm::SmallVectorBase<unsigned int>::mallocForGrow(unsigned long, unsigned long, unsigned long&)'
/bin/ld: ../lib/libterra_s.a(ASTUnit.cpp.o): in function `clang::ASTUnit::Save(llvm::StringRef)':
ASTUnit.cpp:(.text._ZN5clang7ASTUnit4SaveEN4llvm9StringRefE+0x119): undefined reference to `llvm::writeFileAtomically(llvm::StringRef, llvm::StringRef, std::function<llvm::Error (llvm::raw_ostream&)>)'
/bin/ld: ../lib/libterra_s.a(ASTUnit.cpp.o): in function `llvm::SmallVectorTemplateBase<clang::StoredDiagnostic, false>::grow(unsigned long)':
ASTUnit.cpp:(.text._ZN4llvm23SmallVectorTemplateBaseIN5clang16StoredDiagnosticELb0EE4growEm[_ZN4llvm23SmallVectorTemplateBaseIN5clang16StoredDiagnosticELb0EE4growEm]+0x28): undefined reference to `llvm::SmallVectorBase<unsigned int>::mallocForGrow(unsigned long, unsigned long, unsigned long&)'
/bin/ld: ../lib/libterra_s.a(ASTUnit.cpp.o): in function`llvm::SmallVectorTemplateBase<clang::ASTUnit::StandaloneDiagnostic, false>::grow(unsigned long)':
<snipped>
Then I've followed instructions in a README.md and built LLVM 18 (llvm-18.1.3) from source. Instruction in a README missed several steps important for successful LLVM build. Building terra with LLVM 18 is failed on a linkage due to error:
[100%] Linking CXX executable ../bin/terra
[100%] Built target TerraLibraryShared
[100%] Generating ../lib/terra.so
[100%] Built target TerraLibrarySymlink
/bin/ld: ../lib/libterra_s.a(tcwrapper.cpp.o):(.data.rel.ro._ZTI12CodeGenProxy[_ZTI12CodeGenProxy]+0x10): undefined reference to `typein
fo for clang::ASTConsumer'
collect2: error: ld returned 1 exit status
gmake[2]: *** [src/CMakeFiles/TerraExecutable.dir/build.make:199: bin/terra] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:403: src/CMakeFiles/TerraExecutable.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
According to advice in ^1 I've rebuilt terra with CXXFLAGS=-fno-rtti
and terra builds successfully. But on start:
: CommandLine Error: Option 'o' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options
Aborted (core dumped)
Please help.
terra: release-1.2.0-4-g7faa246
I don't have Ubuntu 22.04 personally, so I am using Docker to build. But this should give you a basis for debugging—if it works here and not on your machine, maybe you have some difference in your system configuration that is causing problems.
Note that the LLVM 18 source build is slightly different because LLVM changed the source distribution layout, but that other than the combined tarball and one additional flag -DLLVM_ENABLE_PROJECTS='clang'
, everything should be basically the same.
One other thing I'll mention: link errors like what you show me are relatively unusual. I actually cannot think of the last time I've seen something like that. I wonder if it's possible that you're not actually using your source builds of LLVM. If you accidentally mixed builds or used the wrong one, that would be a classic way to get the errors you indicated.
Dockerfile.ubuntu22-llvm13
:
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update -qq && \
apt-get install -qq build-essential cmake git wget libpython3-dev python3-pip && \
apt-get clean
RUN wget https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/llvm-13.0.0.src.tar.xz && \
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/clang-13.0.0.src.tar.xz && \
tar xf llvm-13.0.0.src.tar.xz && \
tar xf clang-13.0.0.src.tar.xz && \
mv clang-13.0.0.src llvm-13.0.0.src/tools/clang && \
mkdir build install && \
cd build && \
cmake ../llvm-13.0.0.src -DCMAKE_INSTALL_PREFIX=$PWD/../install -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_LIBEDIT=OFF -DLLVM_ENABLE_ZLIB=OFF -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_ENABLE_ASSERTIONS=OFF && \
make install -j20 && \
rm -rf build llvm-13.0.0.src *.tar.xz
RUN git clone https://github.com/terralang/terra.git && \
cd terra/build && \
cmake .. -DCMAKE_INSTALL_PREFIX=$PWD/../install -DCMAKE_PREFIX_PATH=$PWD/../../install && \
make install -j20 && \
ctest -j20
Build with:
docker build -f Dockerfile.ubuntu22-llvm13 .
Note that you may want to adjust the -j
parameters to fit your machine.
Dockerfile.ubuntu22-llvm18
:
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update -qq && \
apt-get install -qq build-essential cmake git wget libpython3-dev python3-pip && \
apt-get clean
RUN wget https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/llvm-project-18.1.8.src.tar.xz && \
tar xf llvm-project-18.1.8.src.tar.xz && \
mkdir build install && \
cd build && \
cmake ../llvm-project-18.1.8.src/llvm -DCMAKE_INSTALL_PREFIX=$PWD/../install -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_LIBEDIT=OFF -DLLVM_ENABLE_ZLIB=OFF -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_ENABLE_ASSERTIONS=OFF -DLLVM_ENABLE_PROJECTS='clang' && \
make install -j20 && \
rm -rf build llvm-project-18.1.8.src *.tar.xz
RUN git clone https://github.com/terralang/terra.git && \
cd terra/build && \
cmake .. -DCMAKE_INSTALL_PREFIX=$PWD/../install -DCMAKE_PREFIX_PATH=$PWD/../../install && \
make install -j20 && \
ctest -j20
Build with:
docker build -f Dockerfile.ubuntu22-llvm18 .
Many thanks! Finally, I can build it with LLVM 18.
Compiled using CMake:
Backtrace:
Distributor ID: Ubuntu Description: Ubuntu 22.04.4 LTS Release: 22.04 Codename: jammy
Similar issue: https://github.com/terralang/terra/issues/357