Building on FreeBSD fails to find -lzstd
Zig Version
3d1652070acd01b7c871615702916425cd292a8a
Steps to Reproduce and Observed Behavior
On FreeBSD 14.0, run:
git clone https://github.com/ziglang/zig
cd zig
cmake -B build -DCMAKE_BUILD_TYPE=Release -G 'Ninja'
cd build
ninja
Output:
> ninja
[1/2] Linking CXX executable zig2
FAILED: zig2
: && /usr/bin/c++ -O3 -DNDEBUG -Wl,-z,stack-size=0x10000000 CMakeFiles/zig2.dir/zig2.c.o CMakeFiles/zig2.dir/compiler_rt.c.o -o zig2 -L/usr/local/llvm17/lib -Wl,-rpath,/usr/local/llvm17/lib zigcpp/libzigcpp.a /usr/local/llvm17/lib/libclang-cpp.so.17 /usr/local/llvm17/lib/liblldMinGW.a /usr/local/llvm17/lib/liblldELF.a /usr/local/llvm17/lib/liblldCOFF.a /usr/local/llvm17/lib/liblldWasm.a /usr/local/llvm17/lib/liblldMachO.a /usr/local/llvm17/lib/liblldCommon.a -lLLVM-17 -lrt -lexecinfo -lpthread -lm -lz -lzstd -lpthread -lm -lz -lzstd && :
ld: error: unable to find library -lzstd
ld: error: unable to find library -lzstd
c++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
Expected Behavior
It should build without problem.
Additional Details
zstd is installed at /usr/local
> pkg list zstd
/usr/local/bin/unzstd
/usr/local/bin/zstd
/usr/local/bin/zstd-frugal
/usr/local/bin/zstdcat
/usr/local/bin/zstdgrep
/usr/local/bin/zstdless
/usr/local/bin/zstdmt
/usr/local/include/zdict.h
/usr/local/include/zstd.h
/usr/local/include/zstd_errors.h
/usr/local/lib/cmake/zstd/zstdConfig.cmake
/usr/local/lib/cmake/zstd/zstdConfigVersion.cmake
/usr/local/lib/cmake/zstd/zstdTargets-release.cmake
/usr/local/lib/cmake/zstd/zstdTargets.cmake
/usr/local/lib/libzstd.a
/usr/local/lib/libzstd.so
/usr/local/lib/libzstd.so.1
/usr/local/lib/libzstd.so.1.5.5
/usr/local/libdata/pkgconfig/libzstd.pc
/usr/local/man/man1/unzstd.1.gz
/usr/local/man/man1/zstd.1.gz
/usr/local/man/man1/zstdcat.1.gz
/usr/local/man/man1/zstdgrep.1.gz
/usr/local/man/man1/zstdless.1.gz
/usr/local/man/man1/zstdmt.1.gz
/usr/local/share/licenses/zstd-1.5.5/BSD3CLAUSE
/usr/local/share/licenses/zstd-1.5.5/GPLv2
/usr/local/share/licenses/zstd-1.5.5/LICENSE
/usr/local/share/licenses/zstd-1.5.5/catalog.mk
Workaround: edit CMakeCache.txt manually.
//Flags used by the CXX compiler during all build types.
CMAKE_CXX_FLAGS:STRING=-L/usr/local/lib
Workaround: edit
CMakeCache.txtmanually.//Flags used by the CXX compiler during all build types. CMAKE_CXX_FLAGS:STRING=-L/usr/local/lib
The official guide recommends using -DCMAKE_PREFIX_PATH, eg -DCMAKE_PREFIX_PATH="/usr/local/llvm18;/usr/local;/usr/local/lib"
I still think it's better to hard-code the library path for FreeBSD.
pkgconf --libs libzstd also works on FreeBSD.
please file bug in LLVM project, the dependency is supposed to be communicated with llvm-config.
The upstream label could probably be added here.