且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

find_library或link_directories或find_package?什么是更好的方法?错误 - 使用cmake链接库

更新时间:2021-06-30 04:03:03

是方法1.

link_directories


请注意,此命令很少需要。 find_package()和find_library()返回的库位置是绝对路径。将这些绝对库文件路径直接传递给target_link_libraries()命令。 CMake将确保链接器找到它们。

Note that this command is rarely necessary. Library locations returned by find_package() and find_library() are absolute paths. Pass these absolute library file paths directly to the target_link_libraries() command. CMake will ensure the linker finds them.

无论你采取什么方法,我不知道一个简单的方法来自动获得这些子依赖关系的列表并添加它们。我每次只要做一个 find_package find_library

Regardless of the approach you take, I don't know of an easy way to automatically get the list of these "sub-dependencies" and add them. I'd just do a find_package or find_library for each.

至少这样,如果没有找到依赖项,您的项目将在CMake配置时间而不是链接时失败。

At least that way, if a dependency isn't found, your project fails at CMake configure time rather than at link time.