.mm c++ oc 混编

When you create a static library you don't link in the dependent libraries. As a result, when you rename one of the files from .m to .mm it starts to now depend on C++ features such as stack unwinding when receiving exceptions. Even if you tell the compiler that you have no intent of using exceptions (by the denial of C++ exceptions in the compile flags), it still needs to known the potential mechanism for stack unwinding (this is what the personality variable means).

The reason why the template apps from Cocos2d+Box2d don't have this problem is that they possess some .mm files; as a result the c++ compiler is used to perform the final link, which pulls in the c++ library automatically.

 

https://stackoverflow.com/questions/18804414/xcode-why-does-renaming-to-mm-fail-with-undefined-symbol-gxx-personality-s

转载于:https://www.cnblogs.com/feng9exe/p/7999181.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Fortran和C++可以通过一些接口来实现混编,以下是一个简单的示例: 首先是Fortran程序,其中包含了一个Fortran函数和一个接口: ``` ! sample.f90 module sample implicit none contains ! Fortran函数 real function func(x) real, intent(in) :: x func = x**2 + 2*x + 1 end function func ! 接口 interface real function cplusplus_func(x) bind(C, name="cplusplus_func") import :: C_DOUBLE real(C_DOUBLE), intent(in) :: x end function cplusplus_func end interface end module sample ``` 接着是C++程序,其中包含了一个C++函数和一个接口: ``` // sample.cpp #include <iostream> using namespace std; extern "C" { // C++函数 double cplusplus_func(double x) { return x*x + 2*x + 1; } // 接口 extern double func_(double *x); } int main() { double x = 2.0; // 调用C++函数 double y = cplusplus_func(x); cout << "C++ function: " << y << endl; // 调用Fortran函数 double z = func_(&x); cout << "Fortran function: " << z << endl; return 0; } ``` 在C++程序中,我们使用了`extern "C"`来声明C++函数和接口,以便在链接时能够正确地找到它们。在主函数中,我们首先调用了一个C++函数,然后通过接口调用了一个Fortran函数。 编译Fortran程序时,需要使用`-c`选项生成静态库文件: ``` $ gfortran -c sample.f90 ``` 编译C++程序时,需要链接静态库文件,并使用`-lstdc++`选项链接C++标准库: ``` $ g++ sample.cpp sample.o -lstdc++ ``` 运行程序,可以得到如下输出: ``` C++ function: 9 Fortran function: 9 ``` 说明我们成功地实现了Fortran和C++混编

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值