参考自:http://mrjoelkemp.com/2012/01/getting-started-with-jni-and-c-on-osx-lion/
1 ,创建HelloWorld,如:
说明:声明native本地方法,在运行HelloWorld时先加载名为"HelloWorld"的动态链接库文件
2,javac编译生成class文件,并javah -jni生成符合jni规则的头文件,如:
3,创建C++文件,如:
4,g++编译c++源文件为对象文件,并指定选项以包含Header路径,如:
5,生成Mac上的动态链接文件,如:
6,执行,VeryGood:
二,带参数传递:
就如声明普通的java方法一样,只不过用native修饰,并且不提供实现,与上面类似:编译,生成头文件,创建g++源文件,在实现头文件中的方法时需注意【jstring 是类型,需要声明本地变量接收传来的参数】,如:
头文件方法为:
在实现时:
其他就完全一样了。
OK。