libraries将绝对路径作为库路径的平台库名称扩展

libraries将绝对路径作为库路径的平台库名称扩展

本文介绍了使用target_link_libraries将绝对路径作为库路径的平台库名称扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CMake中使用target_link_libraries只使用库名称,例如

Using target_link_libraries in CMake with just the library name, e.g.

target_link_library( myProject SomeLibrary )

会将SomeLibrary扩展为SomeLibrary.lib,libSomeLibrary.so等,具体取决于平台。但是,如果指定了完整路径,则不会基于平台扩展库名称,例如

will expand SomeLibrary to SomeLibrary.lib, libSomeLibrary.so, etc. depending on platform. However, if a full path is specified then the library name is not expanded based on platform, e.g.

target_link_library( myProject ${myProject_SOURCE_DIR}/libs/SomeLibrary )

如何获得基于平台扩展的库名?目前,我在脚本中检测平台,并自己调整库名称感觉有点丑陋。

How can I get the library name to be expanded based on platform? Currently, I'm detecting platform in the script and adjusting the library names myself which feels a little ugly.

(背景:over 我建议在指定库时使用绝对路径,而不是使用link_directories)

(Background: over on this question I'm advised to use absolute paths when specifying libraries rather than using link_directories)

推荐答案

使用。

完整的路径,你应该只给出库的名称和一个列表(可能是可配置的)的位置,它可以找到,并且 find_library 做剩下的。如果成功, find_library 调用的结果可以直接进入 target_link_libraries

Instead of hardcoding the full path, you should only give the name of the library and a list of (possibly configurable) locations where it might be found and have find_library do the rest. If successful, the result of the find_library call can be fed right into target_link_libraries.

这篇关于使用target_link_libraries将绝对路径作为库路径的平台库名称扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 17:55