混合目标C,(* .m,* .mm& .c / .cpp)文件 [英] Mixing Objective C ,(*.m , *.mm & .c /.cpp ) files

查看:169
本文介绍了混合目标C,(* .m,* .mm& .c / .cpp)文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中Core库是C / C ++文件的一部分,而UI需要在Objective C中开发,
我可以从Objective C / .mm文件访问/调用C ++函数
但是反向没有运气到目前为止,即我不能从C ++文件中调用Objective C函数,
当我试图包括Objective C头甚至系统头

In my project Core libraries are part of C/C++ files, while UI needs to be developed in Objective C, I am able to access/Call C++ functions from Objective C/.mm files but reverse no luck so far, i.e. i am not able to call Objective C functions from C++ Files, when i tried to include Objective C header even system header

#import <foundation/foundation.h> 

遇到1000+以上的编译错误,

getting around 1000+ compilation error,

/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:180:0 /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:180: error: expected unqualified-id before '@' token


/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:182:0 /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:182: error: expected initializer before '*' token


/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:183:0 /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:183: error: 'NSString' was not declared in this scope


/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:183:0 /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:183: error: 'aSelectorName' was not declared in this scope

我缺少一些预编译标志等。
任何人都可以建议我,调用/访问目标的最佳方法C类,它继承自NSObject,不需要修改太多的C ++代码,我只需要调用一个函数

Am i missing some pre-compile flag etc.. can anyone suggest me, the best possible way to call/access objective C class which is inherited from NSObject, without modifying much C++ code, i just need to call one function

代码结构/包含头文件的顺序是

Code structure / Order to include header files are

Some system header file
Some Core Class Header file 

#import <foundation/foundation.h>


推荐答案

如果你有一个.cpp文件,还需要使用Objective-C,将.cpp文件重命名为.mm或将 -x objective-c ++ 传递给编译器。

If you have a .cpp file with C++ code that needs to use Objective-C as well, either rename that .cpp file to .mm or pass -x objective-c++ to the compiler.

这篇关于混合目标C,(* .m,* .mm&amp; .c / .cpp)文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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