# find\_library unable to find library even with HINTS/PATHS

**URL:** <https://discourse.cmake.org/t/find-library-unable-to-find-library-even-with-hints-paths/4851>\
**Category:** Code\
**Tags:** os:linux, gen:makefiles\
**Created:** [January 14, 2022, 3:58am UTC](https://discourse.cmake.org/t/find-library-unable-to-find-library-even-with-hints-paths/4851 "2022-01-14T03:58:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zwimer](https://discourse.cmake.org/user_avatar/discourse.cmake.org/zwimer/32/2106_2.png) [@zwimer](https://discourse.cmake.org/u/zwimer)\
**Post date:** [January 14, 2022, 3:58am UTC](https://discourse.cmake.org/t/find-library-unable-to-find-library-even-with-hints-paths/4851/1 "2022-01-14T03:58:04Z")

</div>

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:

```auto
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:

```auto
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:

```auto
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:

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

```

And the output was:

```auto
/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!

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [January 14, 2022, 8:35am UTC](https://discourse.cmake.org/t/find-library-unable-to-find-library-even-with-hints-paths/4851/2 "2022-01-14T08:35:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MichaelZhou](https://discourse.cmake.org/user_avatar/discourse.cmake.org/michaelzhou/32/4719_2.png) [@MichaelZhou](https://discourse.cmake.org/u/MichaelZhou)\
**Post date:** [July 3, 2024, 7:18am UTC](https://discourse.cmake.org/t/find-library-unable-to-find-library-even-with-hints-paths/4851/3 "2024-07-03T07:18:11Z")

</div>

I have the same problem. find\_path cannot find an exsist path.

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

```

shows

```log
[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.

```bash
# 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

```

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [July 3, 2024, 7:30am UTC](https://discourse.cmake.org/t/find-library-unable-to-find-library-even-with-hints-paths/4851/4 "2024-07-03T07:30:16Z")

</div>

> [@MichaelZhou](#):
>
> `HINTS ";${QNX_AP_PATH}/AMSS/inc"`

Is the semicolon a typo?

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [July 3, 2024, 7:32am UTC](https://discourse.cmake.org/t/find-library-unable-to-find-library-even-with-hints-paths/4851/5 "2024-07-03T07:32:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MichaelZhou](https://discourse.cmake.org/user_avatar/discourse.cmake.org/michaelzhou/32/4719_2.png) [@MichaelZhou](https://discourse.cmake.org/u/MichaelZhou)\
**Post date:** [July 3, 2024, 7:44am UTC](https://discourse.cmake.org/t/find-library-unable-to-find-library-even-with-hints-paths/4851/6 "2024-07-03T07:44:29Z")

</div>

find\_path log is :

```log
/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:

```log
// ....
/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?

---

<div class="post-metadata">

**Author:** ![MichaelZhou](https://discourse.cmake.org/user_avatar/discourse.cmake.org/michaelzhou/32/4719_2.png) [@MichaelZhou](https://discourse.cmake.org/u/MichaelZhou)\
**Post date:** [July 3, 2024, 7:49am UTC](https://discourse.cmake.org/t/find-library-unable-to-find-library-even-with-hints-paths/4851/7 "2024-07-03T07:49:27Z")

</div>

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

Problem solved!
