问题描述
遗憾的是,CMake遵循笨拙的隐式lib"约定,当库名称实际上未遵循该约定(例如zlib)或将"lib"作为其名称的显式部分时,不可避免地会引起问题.
Sadly, CMake follows the awkward "implicit lib" convention, which inevitably causes problems when library names don't actually follow the convention (e.g. zlib), or have 'lib' as an explicit part of their name.
例如,假设我要添加libusb:
For example, suppose I want to add libusb:
add_library(libusb ...)
在Windows上,这将正确生成 libusb.lib
.在Unix上,它将生成有趣的 liblibusb.a
.有什么办法可以防止这种行为?我知道我可以使用 OUTPUT_NAME
,但是我必须使用一些时髦的生成器表达式来在Windows上保留 libusb.lib
.我想知道是否有更好的方法?
On Windows this will correctly produce libusb.lib
. On Unix it will produce the hilarious liblibusb.a
. Is there any way to prevent this behaviour? I know I can set the output name explicitly using OUTPUT_NAME
but I'd have to use some funky generator expressions to preserve libusb.lib
on Windows. I wonder if there is a better way?
(而且没有 add_library(usb ...
不是解决方案;该库称为 libusb 而不是 usb .)
(And no add_library(usb ...
is not a solution; the library is called libusb not usb.)
推荐答案
您可以通过 CMAKE_STATIC_LIBRARY_PREFIX
.因此,就您而言,只需在 project()
命令之后执行:
You can modify it via CMAKE_STATIC_LIBRARY_PREFIX
. So in your case just do after your project()
command:
set(CMAKE_STATIC_LIBRARY_PREFIX "")
或者您可以通过 PREFIX
目标属性.
Or you can change it per target via the PREFIX
target property.
这篇关于停止CMake从`lib`到库名的前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!