使用cmake,如何将由external_project语句构建的对象文件链接到另一个库? [英] Using cmake, how to link an object file built by an external_project statement into another library?
问题描述
在我们的项目中,我们想要使用第三方库(A),它使用自动工具构建,并生成一个对象文件(B),我们需要一个我们的库(C)的@链接时间。 p>
external_project(
A
...
)
set_source_files_properties A)
add_library(C ... A)
add_dependency(CB)
我有一个印象,这应该做的伎俩,但cmake命令失败,说明它在检查add_library期间找不到文件A.
任何修复或替代解决方案将非常感谢! (更改第三方库不是一个选项)
感谢!
这里有几个问题:
-
external_project
应为ExternalProject_Add
- 源文件没有名为
DEPEND
的属性可用 -set_source_files_properties
命令在此无效。 (以下是源文件上的属性) / li>
-
add_library
期望传递源文件列表,而不是另一个CMake目标(A
) -
add_dependency
应为add_dependencies
除了那些4行,它是OK: - )
所以问题是你想包括对象文件 B在
,但是它不会在configure-time(当CMake被调用时) p> add_library
调用中的
我想你将要做如下事情:
ExternalProject_Add(
A
...
)
set_source_files_properties(
$ {B} PROPERTIES
EXTERNAL_OBJECT TRUE#标识为对象文件
GENERATED TRUE#在配置时不需要文件存在
)
add_library(C ... $ {B})
In our project, we want to use a third-party library (A) which is built using autotools and which generates an object file (B) which we need @ link time of one of our libraries (C).
external_project(
A
...
)
set_source_files_properties(B PROPERTIES DEPEND A)
add_library(C ... A)
add_dependency(C B)
I had the impression that this should do the trick, but the cmake command fails by stating that it cannot find file A during the check for add_library.
Any fixes or alternative solutions would be greatly appreciated! (changing the third-party library is not an option) thanks!
There are a few issues here:
external_project
should beExternalProject_Add
- Source files have no property called
DEPEND
available - theset_source_files_properties
command has no effect here. (Here are the properties available on source files) add_library
expects a list of source files to be passed, not another CMake target (whichA
is)add_dependency
should beadd_dependencies
Apart from those 4 lines it's all OK :-)
So the issue is going to be that you want to include the object file B
in the add_library
call, but it's not going to be available at configure-time (when CMake is invoked), only at build time.
I think you're going to have to do something like:
ExternalProject_Add(
A
...
)
set_source_files_properties(
${B} PROPERTIES
EXTERNAL_OBJECT TRUE # Identifies this as an object file
GENERATED TRUE # Avoids need for file to exist at configure-time
)
add_library(C ... ${B})
这篇关于使用cmake,如何将由external_project语句构建的对象文件链接到另一个库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!