简体   繁体   English

一起构建Swift,Objective-C和静态C ++库

[英]Building Swift, Objective-C and a Static C++ Library Together

I have a static library from a third-party SDK — it's the FIT SDK that encodes and decodes "Flexible & Interoperable Data Transfer Protocol", used for various sports and fitness equipment. 我有一个来自第三方SDK的静态库-它是FIT SDK,它可以编码和解码用于各种运动和健身设备的“灵活且可互操作的数据传输协议”。 It's a binary format, well-described in the SDK, which also comes with a bunch of CPP, C-Sharp and Objective-C examples — plus a static library built from CPP source. 它是一种二进制格式,在SDK中有很好的描述,还附带了一堆CPP,C-Sharp和Objective-C示例-以及从CPP源构建的静态库。

From what everyone seems to say, I should be able to build my Swift app with the static library, including the requisite bridging header. 从每个人看来,我应该能够使用静态库(包括必需的桥接头)构建我的Swift应用程序。

I made a screenflow ( https://vimeo.com/205082135 ) showing what happens, which is why I'm here. 我做了一个屏幕流( https://vimeo.com/205082135 ),显示发生了什么,这就是为什么我在这里。

I can get Xcode 8 (beta 3) to build a new, fresh project containing the library and even some Objective-C code. 我可以获得Xcode 8(测试版3)来构建一个包含库甚至一些Objective-C代码的新项目。 As soon as I add the bridging header, even with a rudimentary include, XCode craters with a Linker error, complaining that it can't find some class from the standard C++ library, like or . 一旦添加了桥接标头(即使是基本的include),带有链接器错误的XCode弹坑,就会抱怨它无法从标准C ++库(例如或)中找到某些类。 Smells like a configuration management issue with Xcode that I simply cannot sort out. 闻起来像Xcode的配置管理问题,我根本无法解决。

My sample project with the library is here: https://github.com/bleeckerj/Xcode-FIT-TEST 我的带有库的示例项目在这里: https : //github.com/bleeckerj/Xcode-FIT-TEST

Has anyone seen this sort of thing before? 有人看过这种东西吗?

So, through some help and lots of time and trials I managed to solve the problem and answer my own question. 因此,通过一些帮助,大量的时间和尝试,我设法解决了问题并回答了自己的问题。

Effectively one needs an Objective-C wrapper around the C++ (or Objective-C++) class containing the code one wants to expose and call from Swift. 实际上,需要一个围绕C ++(或Objective-C ++)类的Objective-C包装,其中包含一个您想公开并从Swift调用的代码。 Then there's the Bridging Header that exposes just that Objective-C class. 然后是只显示该Objective-C类的桥接头。 This particular Bridging Header is This sounds easy, and now it in fact is easy — but it was a mystery to me. 这个特定的桥接标题是:这听起来很容易,但现在实际上容易-但这对我来说还是个谜。 It's a long-ish story, so I explain it as part of a sample repository https://github.com/bleeckerj/fit-sdk-with-swift derived from the FIT SDK that answers the question with an example. 这是一个很长的故事,因此我将其作为示例存储库https://github.com/bleeckerj/fit-sdk-with-swift的一部分进行解释,该示例存储库是从FIT SDK派生的,并通过示例回答了该问题。

Hope this is able to help anyone who comes across this problem. 希望这能够对遇到此问题的任何人有所帮助。

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

相关问题 将Objective-C应用程序链接到C ++静态库 - Link Objective-C application to C++ static library 如何在Objective-C中包装庞大的静态C ++库? - How to wrap a huge static C++ library in Objective-C? 构建静态C ++库以与Xcode 4中的Objective-c应用程序一起使用 - Building static C++ lib for use with Objective-c app in Xcode 4 在C ++命令行工具项目中使用Objective-C / C静态库 - Using Objective-C/C static library in C++ command line tool project C ++静态库:在包装器/桥接器中实现对本机移动方法的定义(Java,Objective-C) - C++ static library: implement definitions in wrappers/bridges toward native mobile methods (Java, Objective-C) 链接静态C ++库时,Objective-C中的符号表发生了变化 - Mangled symbol table in Objective-C when linking static C++ library 如何在XCode 4.2中一起使用c ++和Objective-c - How to use c++ and objective-c together in XCode 4.2 如何在Xcode Objective-C项目中的.mm类扩展中导入/使用快速静态库/框架 - How to import/use swift static library/framework in to .mm class extension in Xcode Objective-C Project 从Objective-C访问静态C ++字段 - Access to a static c++ field from objective-c C ++中的静态初始化与Objective-C混合 - Static initialization in C++ mixed with Objective-C
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM