导出导入的库 [英] Exporting an imported library

查看:105
本文介绍了导出导入的库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有projectA,我正在其中导入一个库,其中包括:

I have projectA, into which I'm importing a library with:

add_library(foo STATIC IMPORTED)
set_property(TARGET foo PROPERTY IMPORTED_LOCATION /path/to/foo.a)

然后我用 foo 在项目中的多个位置,都可以正常工作。

I then use foo in several places within the project, and it all works fine.

我想导出几个目录级别在此项目中构建的库,可用于完全断开CMake配置的另一个项目。我有:

A couple of directory levels down I want to export a library built within this project for use in yet another project with a completely disconnected CMake config. I've got:

...
target_link_libraries(thislib foo)
export(TARGETS thislib FILE /path/to/thislib.cmake)

虽然导入项目B也需要foo(因为导入的库需要它),并抱怨它找不到-lfoo 。我尝试将其添加到 export 命令中,但随后得到:

The importing projectB also needs foo though (because the imported library needs it), and complains that it cannot find -lfoo. I tried adding it to the export command, but then I get:

CMake Error at thislib/CMakeLists.txt:37 (export):
  export given target "foo" which is not built by this project.

我只想将本地使用的配置导出到其他(导入)项目。我不想直接告诉projectB有关 foo 的信息。有什么方法可以做到这一点?

I just want to export the same configuration I use locally to the other (importing) project. I don't want to have to tell projectB about foo explicitly. Is there some way to accomplish this?

推荐答案

我没有找到上述问题的实际解决方案,但是我发布了自己的解决方法,以备将来参考。

I did not find an actual solution for the problem as stated, but am posting my own workaround for future reference.

我意识到发出了 foo 依赖项 在出口;它只是没有路径。而且由于我仍然没有弄清楚如何获取cmake来导出路径,因此我将 export 命令恢复为上面问题中显示的命令(没有 foo )。

I realized that the foo dependency was being emitted in the export; it just didn't have a path with it. And since I still haven't figured out how to get cmake to export the path along with it, I reverted my export command to that shown in the question above (without foo).

然后我回到原来的位置,这里是 foo 正在导入并删除了 add_library set_property ,并用以下内容替换了它们:

Then I went back to the original place where foo was being imported and removed the add_library and set_property, replacing them with this:

set(foo /path/to/foo.a)

然后将 target_link_libraries 更改为:

target_link_libraries(thislib ${foo})

换句话说,不是使它成为真正的导入库,这只是原始库路径。确实可以正确地将其写入导出文件,并允许projectB链接。

In other words, rather than making it a real "imported library", it's just a raw library path. This does get correctly written into the export file and allows projectB to link.

这篇关于导出导入的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆