简体   繁体   English

如何使用c ++源代码和静态库创建iOS Framework

[英]How to create iOS Framework with c++ sources and static libraries

I have c++ source code and some 3rd parties static libraries, which code is using. 我有c ++源代码和一些第三方静态库,代码正在使用。 And I have a simple iOS application, which runs this code. 我有一个简单的iOS应用程序,它运行此代码。 Basically, there are such modules: 基本上,有这样的模块:

  1. ios app ios app
  2. my_lib.a my_lib.a
  3. 3rd party static libs 第三方静态库

And dependencies: ios_app -> my_lib.a -> 3rd party static libs 和依赖项:ios_app - > my_lib.a - >第三方静态库

Everything works as expected. 一切都按预期工作。

Now I want to create an iOS Framework, which would have my_lib.a and 3rd_party.a, and ios_app would use it. 现在我想创建一个iOS框架,它将拥有my_lib.a和3rd_party.a,而ios_app将使用它。 What I'm doing: 我在做什么:

add_library (my_lib SHARED "")
target_sources(my_lib PRIVATE _my_source_files_)
set_target_properties(my_lib PROPERTIES FRAMEWORK TRUE _OTHER_KEYS_)
target_link_libraries (my_lib _3rd_party_libs)

Then I build Framework and check, what it has with command: nm -gU my_framework.framework/my_framework The thing is, that id does not show symbols from my source file, but only from 3rd party libraries. 然后我构建框架并检查它有什么命令:nm -gU my_framework.framework / my_framework问题是,该id不显示源文件中的符号,而只显示来自第三方库的符号。 As a result, when using such framework, I'm getting compilation error 'symbol not found for architecture ...' 结果,当使用这样的框架时,我得到编译错误'找不到架构的符号......'

On the other hand, if I declare my framework as 'static': 另一方面,如果我将我的框架声明为“静态”:

add_library (my_lib SHARED "")

But after that I did not see all those 3rd party libraries in output, but see symbols from my sources. 但之后我没有看到输出中的所有第三方库,但看到我的来源的符号。

I have googled and did not find any answers or examples. 我用谷歌搜索,没有找到任何答案或例子。 May be I am missing something? 可能是我遗失了什么?

Solution was to export classes in right way. 解决方案是以正确的方式导出类。

  1. generate export header with cmake generate_export_header(...) command https://cmake.org/cmake/help/latest/module/GenerateExportHeader.html ; 使用cmake generate_export_header(...)命令https://cmake.org/cmake/help/latest/module/GenerateExportHeader.html生成导出标头;
  2. Use generated macroses in class declaration, which should be used outside; 在类声明中使用生成的宏,应该在外面使用;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM