I am trying to set up Rust for the first time on windows, I managed to get hello world up and running, but now I need to compile the Z3 library (GitHub - prove-rs/z3.rs: Rust bindings for the Z3 solver.). Unfortunately I keep getting the error:
Unable to generate bindings: ClangDiagnostic("wrapper.h:1:10: fatal error: 'z3.h' file not found\n")
I have found this is supposed to be related to LLVM, so I downloaded LLVM (tried from LLVM Download Page, using winget, as well as some other site), set up LIBCLANG_PATH system variable to point at the .../LLVM/bin location (I also tried just .../LLVM or other subfolders) didnt work. Tho it did produce a different error, namely:
Unable to find libclang: "couldn't find any valid shared libraries matching: ['clang.dll', 'libclang.dll'], set the \LIBCLANG_PATH\ environment variable to a path where one of these files can be found (invalid: [])"
I checked the LLVM install folder for libclang.dll and clang.dll but it only contains libclang.lib and not libclang.dll which is apparently needed... I did find a bunch of files with long names such as clang_rt.asan_dynamic-x86_64.lib even one clang_rt.asan_dynamic-x86_64.dll or clang.exe but setting the LIBCLANG_PATH to any of them did nothing. I also tried searching how to install clang, but every source said it is installed by installing LLVM. Any ideas how to fix this error?
If it matters, I tried to build it in both RustRover as well as visual studio...
I also tried uninstalling everything rust related and reinstalling, same issue.
Did you follow the steps for finding the native z3 library? The rust z3 library is only a wrapper around a c++ library so it is more involved than pure rust code. z3.rs/z3-sys at master · prove-rs/z3.rs · GitHub
The first error seems to me that it can't find the native header
You broke your working libclang install. Libclang is the tool that produced the first ClangDiagnostic error you saw, so your new error seems to be working backwards.
Missing z3. Take a look at the readme for z3. By default, it will look for an already-installed copy of the library. Your initial error appears to be caused by this library missing. You can install z3 itself, which should resolve the issue, or you can leverage one of the alternatives mentioned in the readme.
It does appear the issue is it cannot find the Z3 library. I do have a recent build of the Z3 library while I was working with it in C and C++. In C and C++ it finds the z3.h under the path ...\z3-master\build\libz3.lib. I tried setting the Z3_SYS_Z3_HEADER environment variable to this path but it still cannot find the library with the same error as above. I have also tried setting it to ...\z3-master\build or ...\z3-master but none of these do anything...
Any ideas where the system variable should point so Rust can find the z3.h as well?
according to the documentation, the variable should point directly to the z3.hfile, not the directory containing it. I don't know about z3, but such public header is typically in an include directory, or somewhere under the src directory tree. if you can't find it, consult your C/C++ settings.
I was able to find the z3.h file in the src directory, and set the Z3_SYS_Z3_HEADER to ...\z3-master\src\api\z3.h and visual studio finally compiled it. Thanks. For some reason C compiler finds this file at a completely different place, weird...
But for some reason RustRover still fails the compiling with error: linking with link.exe failed: exit code: 1181...