CMake Finding Libraries on Wrong Path

2019-07-12 12:36发布

I'm trying to use CMake to use a local, 32-bit version of cURL instead of the installed 64-bit one. When I use the CMake command find_library it's still returning the path at /usr/lib/x86_64-linux-gnu/libcurl.so. I've tried using the flags NO_DEFAULT_PATH and NO_SYSTEM_ENVIRONMENT_PATH but still can't force it to look locally first. My code is below:

    find_library(MYCURL NAMES libcurl 
                    HINTS ${MY_CURL_DIR}
                    NO_SYSTEM_ENVIRONMENT_PATH
                    NO_DEFAULT_PATH)

Where I've specified (and verified) that ${MY_CURL_DIR} is looking in the correct place. Any ideas?

标签: curl cmake
1条回答
萌系小妹纸
2楼-- · 2019-07-12 13:11

Are you deleting your CMakeCache.txt between attempts? Or more specifically, the MYCURL entry in your CMakeCache.txt. (This file should exist in the directory you invoke CMake from).

If find_library successfully finds the library, further executions of CMake don't retry to find the same library.

In your command, the NO_SYSTEM_ENVIRONMENT_PATH option is superfluous - NO_DEFAULT_PATH stops any paths other than ${MY_CURL_DIR} being searched.

Also, you probably don't want to search for "libcurl", just "curl" will do. CMake prepends "lib" for you on UNIX systems. For more info run cmake --help-variable CMAKE_FIND_LIBRARY_PREFIXES

If you want to change the default caching behaviour of find_library and force a search every time CMake is run, use unset first:

unset(MYCURL CACHE)
find_library(MYCURL NAMES curl HINTS ${MY_CURL_DIR} NO_DEFAULT_PATH)
查看更多
登录 后发表回答