Compiling Zig (current master branch) on FreeBSD

Sorry to ask, but I’m really not well-versed with cmake and such.

I would like to checkout and build the latest Zig version from the master branch.

What I did (naively):

I installed an older version of zig (do I need this anyway?). Then:

git clone https://github.com/ziglang/zig
mkdir build
cd build
cmake ..
make

Being on version d66f13c90d47, I get:

[ 94%] Linking CXX executable zig2
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)
*** Error code 1

Stop.
make[2]: stopped in /home/jbe/install/zig/build
*** Error code 1

Stop.
make[1]: stopped in /home/jbe/install/zig/build
*** Error code 1

Stop.
make: stopped in /home/jbe/install/zig/build

I assume this is because on FreeBSD, libzstd is installed in /usr/local/lib instead of /usr/lib:

$ ls /usr/local/lib/libzstd.*
/usr/local/lib/libzstd.a
/usr/local/lib/libzstd.so
/usr/local/lib/libzstd.so.1
/usr/local/lib/libzstd.so.1.5.7

Any help how to solve this is appreciated.

Setting CMAKE_PREFIX_PATH might help.

cmake ... -DCMAKE_PREFIX_PATH=/usr/local ...

Also consider setting: -DZIG_STATIC_ZSTD=ON

2 Likes

Thanks, it actually needed both

  • -DCMAKE_PREFIX_PATH=/usr/local
  • -DZIG_STATIC_ZSTD=ON

I actually had tried -DCMAKE_PREFIX_PATH=/usr/local first, but didn’t understand why it wouldn’t work.

Is it supposed to work without these switches on FreeBSD, i.e. should I post an issue report? Or are these kind of problems not targeted at at this stage of development?

1 Like

I think we’d like to make it work without needing those flags, so opening an issue would be reasonable.

4 Likes

I just found a previous issue on this matter that has been closed: Building on FreeBSD fails to find -lzstd · Issue #19617 · ziglang/zig · GitHub.

Some of the recommendations didn’t help either, so I added the currently working workaround as a comment.

Should I file a bug report about the wiki page being outdated? (Or is that quick to fix? I don’t know what’s the “right” way to compile cleanly.)

I filed an issue report:

1 Like