find_library unable to find library even with HINTS/PATHS

I am trying to use cmake 3.22.1 to find the Z3 shared library. To start, here is where my Z3 library is located:

ls /usr/lib64 | grep z3                                                                                                                                                                                                                                                                # Symlink to                                                                                                                                                                                                                                                                      

The line of code I’m trying to get to work is:
find_library(Z3_LIB z3). I have also tried each of the following:

find_library(Z3_LIB NAMES z3)
find_library(Z3_LIB NAMES libz3)
find_library(Z3_LIB NAMES z3 libz3)

At first my assumption was that find_library did not know where to look; so I set CMAKE_LIBRARY_PATH to /usr/lib64. I tried this with CMAKE_FIND_ROOT_PATH and CMAKE_SYSTEM_LIBRARY_PATH.

After that did not work, I tried setting FIND_LIBRARY_USE_LIB64_PATHS to true.

Then I tried all of the above, with each of the variations of find_library. When none of those worked I tried:

find_library(Z3_LIB z3 PATHS "${CMAKE_LIBRARY_PATH}")
find_library(Z3_LIB z3 PATHS ${CMAKE_LIBRARY_PATH})
find_library(Z3_LIB z3 HINTS "${CMAKE_LIBRARY_PATH}")
find_library(Z3_LIB z3 HINTS ${CMAKE_LIBRARY_PATH})

I also verified my variables were valid by doing:

find_library(Z3_LIB z3 PATHS "${CMAKE_LIBRARY_PATH}")

And the output was:


Also, I double checked to see if this was a copy-past error by copying /usr/lib64 from the output into the command ls /usr/lib64 | grep z3 and I did indeed see the two z3 entries.

Finally, I was able to reproduce this on a different version of cmake (a version of 3.21). As such, I imagine it is user error but I am unable to figure out how. I’ve read through the documentation multiple times now and I don’t see what I’m missing.

None of this worked. I’m trying not to add the .so or the .4.8 to the find_library command as I would like this to work cross-platform and not be locked to a specific release of z3. I did try a find_library(Z3_LIB with the CMAKE_LIBRARY_PATH variable set and that did indeed work; however again I’d rather not specify .so nor 4.8 to allow cross-platform version-invariance. Any help would be appreciated!

You must not specify the .so file suffix, that’s correct. But for the linker and cmake to find the library, you must have a file (with no further suffix). Usually, Linux distributions have that in a separate devel package.

1 Like