diffkemp
diffkemp copied to clipboard
Cannot build in Nix when Z3 is installed on the host
When trying to compile DiffKemp in the Nix development environment on Fedora 41, I'm getting errors when I have Nix installed on my system.
Reproducer:
$ nix develop .#diffkemp-llvm16
nix $ mkdir build
nix $ cd build
nix $ cmake .. -GNinja -DCMAKE_BUILD_TYPE=Debug
[...]
[nix] $ ninja
[42/55] Linking CXX executable diffkemp/simpll/diffkemp-simpll
FAILED: diffkemp/simpll/diffkemp-simpll
: && /nix/store/ihhhd1r1a2wb4ndm24rnm83rfnjw5n0z-gcc-wrapper-12.3.0/bin/g++ -fno-rtti -fpic -Wall -Wextra -g diffkemp/simpll/CMakeFiles/simpll.dir/SimpLL.cpp.o -o diffkemp/simpll/diffkemp-simpll -Wl,-rpath,/usr/lib64 diffkemp/simpll/libsimpll-lib.a -lLLVM-16 /usr/lib64/libz3.so.4.13.4.0 && :
/nix/store/3z013mdl9cvpgvavpj19rbilihz4clvi-binutils-2.40/bin/ld: /nix/store/im40dz3167rw55lbg3r5p1f8n4c46x3z-llvm-16.0.6-lib/lib/libLLVM-16.so: undefined reference to `tigetnum@NCURSES6_TINFO_5.0.19991023'
/nix/store/3z013mdl9cvpgvavpj19rbilihz4clvi-binutils-2.40/bin/ld: /nix/store/im40dz3167rw55lbg3r5p1f8n4c46x3z-llvm-16.0.6-lib/lib/libLLVM-16.so: undefined reference to `del_curterm@NCURSES6_TINFO_5.0.19991023'
/nix/store/3z013mdl9cvpgvavpj19rbilihz4clvi-binutils-2.40/bin/ld: /nix/store/im40dz3167rw55lbg3r5p1f8n4c46x3z-llvm-16.0.6-lib/lib/libLLVM-16.so: undefined reference to `set_curterm@NCURSES6_TINFO_5.0.19991023'
/nix/store/3z013mdl9cvpgvavpj19rbilihz4clvi-binutils-2.40/bin/ld: /nix/store/im40dz3167rw55lbg3r5p1f8n4c46x3z-llvm-16.0.6-lib/lib/libLLVM-16.so: undefined reference to `setupterm@NCURSES6_TINFO_5.0.19991023'
/nix/store/3z013mdl9cvpgvavpj19rbilihz4clvi-binutils-2.40/bin/ld: /usr/lib64/libz3.so.4.13.4.0: undefined reference to `std::ios_base_library_init()@GLIBCXX_3.4.32'
/nix/store/3z013mdl9cvpgvavpj19rbilihz4clvi-binutils-2.40/bin/ld: /usr/lib64/libz3.so.4.13.4.0: undefined reference to `__cxa_call_terminate@CXXABI_1.3.15'
collect2: error: ld returned 1 exit status
[54/55] Building CXX object tests/unit_tests/simpll/CMakeFiles/runTests.dir/passes/UnifyMemcpyPassTest.cpp.o
ninja: build stopped: subcommand failed.
I suspect the issue is in this part: https://github.com/diffkemp/diffkemp/blob/ffe6d594d0973dc4d90d15090ef4119b34467ff8/diffkemp/simpll/CMakeLists.txt#L34-L39
We should not prefer system-wide packages over Nix ones. This causes the above error as the system-wide Z3 has apparently been built with GCC version incompatible with the one inside Nix.