Issue 178380
Summary [LLVM] Build error when linking static Z3 library
Labels new issue
Assignees
Reporter Tomahawkd
    When I build LLVM 15.0.7 on centos 7.9 using following commands (static library with static z3)

```
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER="clang++" -DCMAKE_ASM_COMPILER=clang -DLLVM_APPEND_VC_REV=OFF -G Ninja -DLIBCLANG_BUILD_STATIC=ON -DLLVM_STATIC_LINK_CXX_STDLIB=ON -DLLVM_USE_STATIC_ZSTD=ON -DLLVM_ENABLE_TERMINFO=OFF -DBUILD_SHARED_LIBS=OFF -DZLIB_USE_STATIC_LIBS=ON -DLLVM_ENABLE_Z3_SOLVER=ON -DCMAKE_INSTALL_PREFIX=./output -S ./llvm  -B ./build

cmake --build ./build
```
The linker complains about undefined symbol:

```
/usr/local/lib64/libz3.a(scoped_timer.cpp.o): In function `scoped_timer::initialize()':
scoped_timer.cpp:(.text+0x560): undefined reference to `pthread_atfork'
```

The compile command is as follows:

```
/usr/local/bin/clang++ <build options> <lots of llvm static library>  -lrt  -ldl  -lpthread  -lm  /usr/local/lib64/libz3.a lib/libLLVMDemangle.a
```

The question is the `libz3.a` is located after `pthread`.

The relevant CMake code is:

1. linking pthread: [https://github.com/llvm/llvm-project/blob/main/llvm/lib/Support/CMakeLists.txt#L61](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Support/CMakeLists.txt#L61)
2. linking z3: [https://github.com/llvm/llvm-project/blob/main/llvm/lib/Support/CMakeLists.txt#L96](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Support/CMakeLists.txt#L96)

I think this maybe a bug in CMake script, and I have successfully built after I fix it locally. Could you check it out for other platform? Many thanks.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to