python 动态加载库的 CMake 输出名称?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1564696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
CMake output name for dynamic-loaded library?
提问by Anton Kazennikov
I'm trying to write cmake rules to build dynamic-loaded library for python using boost.python on linux. I'd like to use 'foo' for python module name. So, the library must be called foo.so
.
But by default, cmake uses standard rules for library naming, so if I write
我正在尝试编写 cmake 规则以在 linux 上使用 boost.python 为 python 构建动态加载的库。我想使用 'foo' 作为 python 模块名称。因此,必须调用库foo.so
。但是默认情况下,cmake 使用标准的库命名规则,所以如果我写
add_library(foo foo.cpp)
I will get libfoo.so
on output.
Even set_target_properties(foo PROPERTIES OUTPUT_NAME "foobar")
will create libfoobar.so
.
我会得到libfoo.so
输出。甚至set_target_properties(foo PROPERTIES OUTPUT_NAME "foobar")
会创造libfoobar.so
。
How to change this behavior?
如何改变这种行为?
回答by richq
You can unset the prefix with this line:
您可以使用此行取消设置前缀:
set_target_properties(foo PROPERTIES PREFIX "")
回答by dimba
The prefix "lib" is a convention for unix/linux and is exploited widely by compilers (e.g. when you link you write -lfoo).
前缀“lib”是unix/linux 的约定,被编译器广泛利用(例如,当你链接时,你写-lfoo)。
I don't know if you can force cmake to create foo.so instead of libfoo.so, but maybe you can use "libfoo" for python module. Another option is to create install target in cmake ,which will renmae libfoo.so to foo.so
我不知道您是否可以强制 cmake 创建 foo.so 而不是 libfoo.so,但也许您可以将“libfoo”用于 python 模块。另一种选择是在 cmake 中创建安装目标,这将 renmae libfoo.so 到 foo.so