使用 Firebreath 框架将 cocoa 应用程序转换为 NPAPI 插件
我最近发现 Apple 在上一个版本的 Lion 和 Safari 中将不支持 webkit 模型,并且每个人都在迁移到 Firebreath 项目以使用 NPAPI。
我有一个基本的 Cocoa 应用程序,它与以下本机框架链接:
- CoreGraphics
- CoreData
- IOKit
- PFEventTaps (这是一个 3 方框架:Pfiddlesoft.com)
我从未使用过插件,所以这对我来说有点新,我从MAC 教程由 Richard bateman 编写,在遵循指导原则后,我最终为我的个人项目提供了一个 firebreath 项目模板。我所做的下一步只是将所有 Objective-C 类放入源文件文件夹中,添加与 4 个框架的链接,最后我将需要在插件中公开的新公共方法添加到 MyProjectPluinApi.h 例如( registerMethod("MyMethod", make_method(this, &WilmerPlugInAPI::MyMethod ));
当我构建 firebreath 项目时,我收到很多编译错误,其中之一非常重复 是: NSString 未在此范围内声明。
错误指向 NSObjCRuntime.h
到目前为止,我无法使用 XCODE 3.2.6 成功构建此版本,
这里出了什么问题?我需要改变我的所有代码来完成这个模板项目中的CPP风格吗?或者我可以以某种方式链接我的框架? 有一些样本我可以看看吗?
更多详细信息:2011 年 11 月 7 日: 我试图用一个简单的项目进行测试:
- 首先我创建项目 testOfFB
- 它在 /users/Me/Firebreath-dev/build/projects/testofFB 中生成
- ,然后我修改类 testFBApi.cpp 并将其重命名为 testFBApi.mm。
- 我编写了一个名为 testMath.m 的 Objective-c 类,并将其重命名为 testMath.mm
我添加了一个带有签名的方法 Add:
-(long) 添加:(long)a:(long)b:(long)c;
最后我用以下内容修改了文件 testFBApi.mm:
registerMethod("add", make_method(this, &testFBAPI::add ));
在 add 方法的实现中,我创建了 Objective-C 类方法“add”的实例来测试对我的 Objective-的调用 - c 方法。我做了包含并以这种方式更改了文件 /Mac/projectDef.cmake:
target_link_libraries(${PROJECT_NAME} ${PLUGIN_INTERNAL_DEPS} ${Cocoa.framework} // 添加的行 ${Foundation.framework} //添加的行 )
我运行 prepmac.sh 脚本,然后构建 xcode 解决方案,出现相同的错误,而且还没有声明其他一些错误,例如 testFBApi 。
I found recently that webkit model will be unsupported by Apple in Lion and Safari last release and that everybody is migrating to Firebreath project in order to use NPAPI.
I have a basic Cocoa Application which links with the following native frameworks:
- CoreGraphics
- CoreData
- IOKit
- PFEventTaps ( this is a 3 party framework by: Pfiddlesoft.com)
I've never used PlugIns so this is a little new for me, I started with the MAC tutorial written by Richard bateman and after following the guidelines I ends up with a firebreath project template for my personal project. the next step I made was just puting all my Objective-C classes into the Source Files folder adding the linking with the 4 frameworks, finally I added the new public methods I need to expose in the plug-In into the MyProjectPluinApi.h e.g.( registerMethod("MyMethod", make_method(this, &WilmerPlugInAPI::MyMethod ));
When I build the firebreath project I get a lot of compile errors, one of them very repetitive is:NSString was not declared in this scope.
The error points to NSObjCRuntime.h
Until now I can't get this build succesfully with XCODE 3.2.6
what is wrong here? I need to change all my code to accomplish the CPP style in this template project? Or I can link my frameworks in some way?
Is there some sample I can see?
MORE DETAILS: Nov 7 2011:
I was trying to test with a simple project:
- First I create the project testOfFB
- it is generated in /users/Me/Firebreath-dev/build/projects/testofFB
- then I modify the class testFBApi.cpp and rename it to testFBApi.mm.
- I wrote an Objective-c class named testMath.m and rename it to testMath.mm
I add a method Add with the signature:
-(long) Add:(long)a:(long)b:(long)c;
Finally I modify the file testFBApi.mm with this:
registerMethod("add", make_method(this, &testFBAPI::add ));
In the implementation of add method I create an instance of the objective-c class method "add" to test the calling to my objective-c method. I did the includes and I changed the file /Mac/projectDef.cmake in this way:
target_link_libraries(${PROJECT_NAME} ${PLUGIN_INTERNAL_DEPS} ${Cocoa.framework} // added line ${Foundation.framework} //added line )
I run the prepmac.sh script and then build the xcode solution and same errors appear plus some others like testFBApi has not been declared.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果没有更多信息,很难说,但您可能需要更新您的 cmake 文件以导入您需要的框架;如果你在 xcode 中手动执行此操作,它可能也可以工作,但我还没有尝试过这种方式。您应该知道,使用 cmake 添加它不会将其添加到 xcode 中的框架列表中,尽管它应该在那里。
如果需要在同一文件中使用 Objective-C 代码和 C++ 代码,则需要使用 .mm 文件扩展名 (objective-c++),而不是更常见的 .m (objective-c) 扩展名。
除此之外,我需要查看更多代码才能确定可能出了什么问题;例如,我猜您可能缺少包含内容。请注意,如果您的旧项目中有 PCH,那么它很可能不会在新项目中使用。
有关使用 cmake 添加框架的更多信息,请参阅 http://www.firebreath.org/display /文档/使用+库
It's hard to say without a bit more information, but you may need to update your cmake files to import the frameworks you need; if you're doing that by hand in xcode it should probably work as well, but I haven't tried that way. You should know that adding it with cmake will not add it to the framework list in xcode, though it should be there.
If you need to use objective-c code and c++ code in the same file you'll need to use the .mm file extension (objective-c++) rather than the more common .m (objective-c) extension.
Other than this, I'd need to see more of your code to guess what might be wrong for sure; I would guess perhaps you have missing includes, for example. Note that if you had a PCH in your old project it is most likely not being used in the new project.
For more info on adding the frameworks with cmake see http://www.firebreath.org/display/documentation/Using+Libraries