llvm / llvm/llvm-project

[LLVM] Build error when linking static Z3 library

Open
#178,380 2 comments 0 reactions 0 assignees View on GitHub
build-problem
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

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++ -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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.