Android之ndk编译出现"undefined reference to method"解决办法
2017-12-10 21:43
776 查看
1、问题
我自己写了C的头文件和实现的C文件,然后编译成csapp.so库,然后在jni里面写了Android.mk文件和Application.mk文件,配置确保已经没问题,然后csapp.so的位置和头文件都放对了,然后写了一个测试test.cpp文件,然后这个里面调用了csapp.so里面的方法,然后我 ndk-build就出现了下面的错误"undefined reference to method
csapp.h文件
#include <stdio.h> int add(int a, int b);
csapp.c文件
#include "csapp.h" int add(int a, int b) { return a + b; }
test.cpp文件
#include <csapp.h> int function() { return add(1, 2); }
2、分析
我的csapp.so,里面的确实现了这个test.cpp里面调用的方法,然后我的mk文件也的确没有错误,一般出现这个错误提示,要么是没加上这个so依赖,要么就是so里面没有实现这个方法,后面上网查了下
3、原因
是因为我C++文件调用了C语言库的函数,链接找不到,解决办法在,在cpp文件里面的头文件添加extern "C"声明就行test.cpp
extern "C" { #include "csapp.h" } int funcion() { return add(1, 2); }
4、总结
在c++代码中链接c语言的库,要记得在cpp文件里面的C头文件加上 extern "C"包裹相关文章推荐
- 编译WU FTPD出现"undefined reference to crypt"错误解决方法
- 编译出现"undefined reference to `GTK_WIDGET_REALIZED',`GTK_WIDGET_VISIBLE' "相关错误的解决方法
- 用gcc编译.cpp文件可能出现"undefined reference to `__gxx_personality_v0'"问题的解决
- 关于android底层库编译出现“undefined reference to `__android_log_print'”的解决方法
- 用gcc编译.cpp文件可能出现"undefined reference to `__gxx_personality_v0'"问题
- 用gcc编译.cpp文件可能出现"undefined reference to `__gxx_personality_v0'"问题的解决
- 解决coco2dx创建的项目在通过 eclipse ndk编译时报"undefined reference to XXXX "
- 编译QT时出现lib/libQtGui.so: undefined reference to `ts_read_raw'的解决办法
- 解决使用NDK进行编译时出现undefined reference to function的问题
- "android-studio undefined reference to `__android_log_print "错误解决方法
- 编译时出现undefined reference to `libiconv_open’的解决办法
- 用Latex排版论文(3)《控制与决策》初稿LaTex模版编译出现"\bibname undefined"解决办法
- "undefined reference to" 多种可能出现的问题解决方法
- arm编译QT4.8.5时出现lib/libQtGui.so: undefined reference to `ts_read_raw'的解决办法
- 使用Openjdk7编译android源码出现"Could not initialize NSS"错误的解决办法
- 编译3.10内核 出现错误 “undefined reference to...." 解决方法
- 编译3.10内核 出现错误 “undefined reference to...." 解决方法
- 语言中编译连接出现undefined reference to ""的解决方法 (转)
- Qt4.8.5编译qvfb出现undefined reference to `png_create_write_struct'问题解决办法
- NDK 提示"undefined reference to xxx“的解决办法