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                                                                                                                                                                                                                                                        
libz3.so.4.8                 # Symlink to 4.8.14.0                                                                                                                                                                                                                                                                               
libz3.so.4.8.14.0

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:

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

And the output was:

/usr/lib64
Z3_LIB-NOTFOUND

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 libz3.so.4.8) 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 libz3.so (with no further suffix). Usually, Linux distributions have that in a separate devel package.

1 Like

I have the same problem. find_path cannot find an exsist path.

message("${QNX_AP_PATH}/AMSS/inc")
find_path(_PMEM_INCLUDES
  NAMES "pmem.h"
  HINTS ";${QNX_AP_PATH}/AMSS/inc" 
  REQUIRED
  NO_DEFAULT_PATH
)

shows

[cmake] /home/michael/Documents/Repo/Razor/razor-build-qcom/qnx_ap_8650/AMSS/inc
[cmake] CMake Error at CMakeLists.txt:58 (find_path):
[cmake]   Could not find _PMEM_INCLUDES using the following files: pmem.h

however, the path exists.

# find /home/michael/Documents/Repo/Razor/razor-build-qcom/qnx_ap_8650/AMSS/inc -name pmem.h

/home/michael/Documents/Repo/Razor/razor-build-qcom/qnx_ap_8650/AMSS/inc/pmem.h

Is the semicolon a typo?

Use the --debug-find command line arguments to inspect what’s going on.

find_path log is :

/home/michael/Documents/Repo/Razor/razor-build-qcom/qnx_ap_8650/AMSS/inc
CMake Debug Log at cmake/FindPmem.cmake:18 (find_path):
  find_path called with the following settings:

    VAR: PMEM_H
    NAMES: "pmem.h"
    Documentation: Path to a file.
    Framework
      Only Search Frameworks: 0
      Search Frameworks Last: 0
      Search Frameworks First: 0
    AppBundle
      Only Search AppBundle: 0
      Search AppBundle Last: 0
      Search AppBundle First: 0
    CMAKE_FIND_USE_CMAKE_PATH: 1
    CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH: 1
    CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH: 1
    CMAKE_FIND_USE_CMAKE_SYSTEM_PATH: 1
    CMAKE_FIND_USE_INSTALL_PREFIX: 1

  find_path considered the following locations:

There is several path contains /home/michael/Documents/Repo/Razor/razor-build-qcom/qnx_ap_8650/AMSS/inc. They are:

// ....
/home/michael/.qnx/target/qnx7/aarch64le/usr/local/home/michael/Documents/Repo/Razor/razor-build-qcom/qnx_ap_8650/AMSS/inc/pmem.h
// ....
/home/michael/.qnx/target/qnx7/aarch64le/home/michael/Documents/Repo/Razor/razor-build-qcom/qnx_ap_8650/AMSS/inc/pmem.h
// ....
/home/michael/.qnx/target/qnx7/aarch64le/usr/home/michael/Documents/Repo/Razor/razor-build-qcom/qnx_ap_8650/AMSS/inc/pmem.h

//....
/home/michael/Documents/Repo/Razor/razor-build-qcom/qnx_ap_8650/razor-ware/prebuilt/qnx-aarch64/home/michael/Documents/Repo/Razor/razor-build-qcom/qnx_ap_8650/AMSS/inc/pmem.h

// ....
 /home/michael/.qnx/target/qnx7/home/michael/Documents/Repo/Razor/razor-build-qcom/qnx_ap_8650/AMSS/inc/pmem.h

The problem is all paths have a prefix before the PATHS I specified. Why?

after several attemps, I found the find_path and find_library function should add NO_CMAKE_FIND_ROOT_PATH arguments.

Problem solved!