| Issue |
174090
|
| Summary |
[Build] Link error in LLVMDTLTO due to undefined symbols and circular dependency with LLVMLTO (BUILD_SHARED_LIBS=ON)
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
cpist
|
When building LLVM on the main branch with -DBUILD_SHARED_LIBS=ON, the build fails during the linking stage of libLLVMDTLTO.so.
It reports multiple undefined symbols related to llvm::lto.
Environment:
- OS: Windows 11 (WSL2 / Ubuntu 22.04)
To Reproduce I used the following CMake configuration on a WSL2 (Ubuntu) environment:
```
cmake -G Ninja -S llvm -B build \
-DLLVM_ENABLE_PROJECTS="mlir;clang" \
-DLLVM_TARGETS_TO_BUILD="X86" \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DLLVM_USE_LINKER=lld \
-DLLVM_PARALLEL_LINK_JOBS=1 \
-DBUILD_SHARED_LIBS=ON \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DLLVM_CCACHE_BUILD=ON
```
Then run
```
ninja -C build -j4
```
**LInker Error Log**
```
ld.lld: error: undefined symbol: llvm::identify_magic(llvm::StringRef)
>>> referenced by DTLTO.cpp
>>> lib/DTLTO/CMakeFiles/LLVMDTLTO.dir/DTLTO.cpp.o:(llvm::lto::DTLTO::isThinArchive(llvm::StringRef))
ld.lld: error: undefined symbol: llvm::lto::InputFile::getName() const
>>> referenced by DTLTO.cpp
...
ld.lld: error: undefined symbol: llvm::lto::LTO::~LTO()
>>> referenced by DTLTO.cpp
>>> lib/DTLTO/CMakeFiles/LLVMDTLTO.dir/DTLTO.cpp.o:(llvm::lto::DTLTO::~DTLTO())
```
Furthermore, attempting to resolve these symbols by adding LTO to LINK_COMPONENTS in llvm/lib/DTLTO/CMakeLists.txt results in a circular dependency error between LLVMDTLTO and LLVMLTO. If I manually add LTO and BinaryFormat to the LINK_COMPONENTS of LLVMDTLTO, CMake fails with the following message:
```
CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle):
"LLVMDTLTO" of type SHARED_LIBRARY
depends on "LLVMLTO" (weak)
"LLVMLTO" of type SHARED_LIBRARY
depends on "LLVMDTLTO" (weak)
At least one of these targets is not a STATIC_LIBRARY. Cyclic dependencies are allowed only among static libraries.
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs