错误路径上的CMake寻找库 [英] CMake Finding Libraries on Wrong Path

查看:322
本文介绍了错误路径上的CMake寻找库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用CMake使用本地的32位版本的cURL,而不是安装的64位版本。当我使用CMake命令 find_library 时,它仍然返回 /usr/lib/x86_64-linux-gnu/libcurl.so 。我尝试使用标志NO_DEFAULT_PATH和NO_SYSTEM_ENVIRONMENT_PATH,但仍然不能强制它先看本地。我的代码如下:

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)

我已指定(并验证) $ {MY_CURL_DIR} 正在查找正确的位置。任何想法?

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

推荐答案

是否在尝试之间删除 CMakeCache.txt ?或者更具体地,您的 CMakeCache.txt 中的 MYCURL 条目。

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).

如果 find_library 成功找到了库,

在您的命令中, NO_SYSTEM_ENVIRONMENT_PATH 选项是多余的 - NO_DEFAULT_PATH 停止 $ {MY_CURL_DIR} 以外的任何路径。

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

另外,你可能不想搜索libcurl,只是curl会做。 CMake在UNIX系统上为您添加lib。有关更多信息,请运行 cmake --help-variable CMAKE_FIND_LIBRARY_PREFIXES

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

如果要更改默认缓存行为 find_library 并在每次运行CMake时强制搜索,使用取消设置

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)

这篇关于错误路径上的CMake寻找库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆