安卓编译caffe错误 ‘undefined reference to `stderr'’
2018-01-11 15:42
656 查看
NDK:android-ndk-r15c
caffe:https://github.com/sh1r0
编译错误:
[ 76%] Building CXX object src/caffe/CMakeFiles/caffe.dir/util/insert_splits.cpp.o
[ 77%] Building CXX object src/caffe/CMakeFiles/caffe.dir/internal_thread.cpp.o
[ 77%] Linking CXX shared library ../../lib/libcaffe.so
/home/hezheng/caffe-android-lib/android_lib/leveldb/lib/libleveldb.a(port_posix.o): In function `leveldb::port::PthreadCall(char const*, int) [clone .part.0]':
port_posix.cc:(.text.unlikely+0x14): undefined reference to `stderr'
port_posix.cc:(.text.unlikely+0x18): undefined reference to `stderr'
/home/hezheng/caffe-android-lib/android_lib/leveldb/lib/libleveldb.a(env_posix.o): In function `leveldb::(anonymous namespace)::PosixEnv::PthreadCall(char const*, int) [clone .isra.23] [clone .part.24]':
env_posix.cc:(.text+0xc94): undefined reference to `stderr'
env_posix.cc:(.text+0xc98): undefined reference to `stderr'
/home/hezheng/caffe-android-lib/android_lib/leveldb/lib/libleveldb.a(env_posix.o): In function `leveldb::(anonymous namespace)::PosixEnv::~PosixEnv()':
env_posix.cc:(.text+0x245c): undefined reference to `stderr'
/home/hezheng/caffe-android-lib/android_lib/leveldb/lib/libleveldb.a(env_posix.o):env_posix.cc:(.text+0x2490): more undefined references to `stderr' follow
collect2: error: ld returned 1 exit status
src/caffe/CMakeFiles/caffe.dir/build.make:3371: recipe for target 'lib/libcaffe.so' failed
make[2]: *** [lib/libcaffe.so] Error 1
CMakeFiles/Makefile2:272: recipe for target 'src/caffe/CMakeFiles/caffe.dir/all' failed
make[1]: *** [src/caffe/CMakeFiles/caffe.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
错误原因:
在编译leveldb的静态库libleveldb.a时,源文件里面使用了大量的标准IO设备:stderr 等。在NDK15以后,这些都不被支持了,见官方说明文档。编译静态库本身没问题,但是caffe.so链接时就找不到对应的静态库定义了,所以报错。
解决方法:
根据官网,需要给C编译器制定参数 CFLAGS=-D__ANDROID_API__=$API,这里需要把leveldb的Makefile改一下,文件位置leveldb/Makefile
原配置:
CFLAGS += -I. -I./include $(PLATFORM_CCFLAGS) $(OPT)
CXXFLAGS += -I. -I./include $(PLATFORM_CXXFLAGS) $(OPT)
LDFLAGS += $(PLATFORM_LDFLAGS)
LIBS += $(PLATFORM_LIBS)
SIMULATOR_OUTDIR=out-ios-x86
DEVICE_OUTDIR=out-ios-arm
修改后:
CFLAGS += -I. -I./include $(PLATFORM_CCFLAGS) $(OPT) -D__ANDROID_API__=21
CXXFLAGS += -I. -I./include $(PLATFORM_CXXFLAGS) $(OPT) -D__ANDROID_API__=21
LDFLAGS += $(PLATFORM_LDFLAGS)
LIBS += $(PLATFORM_LIBS)
SIMULATOR_OUTDIR=out-ios-x86
DEVICE_OUTDIR=out-ios-arm
这里的21时安卓API的版本号,按照实际情况填写
caffe:https://github.com/sh1r0
编译错误:
[ 76%] Building CXX object src/caffe/CMakeFiles/caffe.dir/util/insert_splits.cpp.o
[ 77%] Building CXX object src/caffe/CMakeFiles/caffe.dir/internal_thread.cpp.o
[ 77%] Linking CXX shared library ../../lib/libcaffe.so
/home/hezheng/caffe-android-lib/android_lib/leveldb/lib/libleveldb.a(port_posix.o): In function `leveldb::port::PthreadCall(char const*, int) [clone .part.0]':
port_posix.cc:(.text.unlikely+0x14): undefined reference to `stderr'
port_posix.cc:(.text.unlikely+0x18): undefined reference to `stderr'
/home/hezheng/caffe-android-lib/android_lib/leveldb/lib/libleveldb.a(env_posix.o): In function `leveldb::(anonymous namespace)::PosixEnv::PthreadCall(char const*, int) [clone .isra.23] [clone .part.24]':
env_posix.cc:(.text+0xc94): undefined reference to `stderr'
env_posix.cc:(.text+0xc98): undefined reference to `stderr'
/home/hezheng/caffe-android-lib/android_lib/leveldb/lib/libleveldb.a(env_posix.o): In function `leveldb::(anonymous namespace)::PosixEnv::~PosixEnv()':
env_posix.cc:(.text+0x245c): undefined reference to `stderr'
/home/hezheng/caffe-android-lib/android_lib/leveldb/lib/libleveldb.a(env_posix.o):env_posix.cc:(.text+0x2490): more undefined references to `stderr' follow
collect2: error: ld returned 1 exit status
src/caffe/CMakeFiles/caffe.dir/build.make:3371: recipe for target 'lib/libcaffe.so' failed
make[2]: *** [lib/libcaffe.so] Error 1
CMakeFiles/Makefile2:272: recipe for target 'src/caffe/CMakeFiles/caffe.dir/all' failed
make[1]: *** [src/caffe/CMakeFiles/caffe.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
错误原因:
在编译leveldb的静态库libleveldb.a时,源文件里面使用了大量的标准IO设备:stderr 等。在NDK15以后,这些都不被支持了,见官方说明文档。编译静态库本身没问题,但是caffe.so链接时就找不到对应的静态库定义了,所以报错。
解决方法:
根据官网,需要给C编译器制定参数 CFLAGS=-D__ANDROID_API__=$API,这里需要把leveldb的Makefile改一下,文件位置leveldb/Makefile
原配置:
CFLAGS += -I. -I./include $(PLATFORM_CCFLAGS) $(OPT)
CXXFLAGS += -I. -I./include $(PLATFORM_CXXFLAGS) $(OPT)
LDFLAGS += $(PLATFORM_LDFLAGS)
LIBS += $(PLATFORM_LIBS)
SIMULATOR_OUTDIR=out-ios-x86
DEVICE_OUTDIR=out-ios-arm
修改后:
CFLAGS += -I. -I./include $(PLATFORM_CCFLAGS) $(OPT) -D__ANDROID_API__=21
CXXFLAGS += -I. -I./include $(PLATFORM_CXXFLAGS) $(OPT) -D__ANDROID_API__=21
LDFLAGS += $(PLATFORM_LDFLAGS)
LIBS += $(PLATFORM_LIBS)
SIMULATOR_OUTDIR=out-ios-x86
DEVICE_OUTDIR=out-ios-arm
这里的21时安卓API的版本号,按照实际情况填写
相关文章推荐
- Caffe 工程的一些编译错误以及解决方案(undefined reference to cv::imread)
- 编译时遇到错误:undefined reference to XXXXXX
- 使用g++编译C/C++程序,链接时出现undefined reference to错误
- GCC编译uboot出现(.ARM.exidx+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'错误的解决办法
- vs2008编译通过,ndk编译有undefined reference to的错误
- Ubuntu11.20 32位linux下编译cppunit报 libcppunit.so: undefined reference to `dlsym'错误问题
- 编译错误undefined reference to `dlsym' 的解决方法
- QT编译出现错误 “undefined reference to ‘vtable for xxx’”
- codeBlocks编译undefined reference to错误
- 编译链接错误undefined reference to
- cocos2d-x在目录..\Classes添加新类的cpp后,在Eclipse下进行混合编译提示”undefined reference to vtable for 新类“错误的解决方法
- eclipse编译openwrt应用程序报Type undefined reference to `pthread_create'错误解决方法
- register.o: undefined reference to symbol 'gpg_strerror'编译错误的解法
- cocos2d-x 使用ndk编译 x86 出现 in function Curl_resolv_timeout: undefined reference to 'sigsetjmp' 错误
- gcc 引用math.h头文件,编译出现undefined reference to `pow‘等错误时,需要加参数-lm.
- Libcurl使用OpenSSL编译出现undefined reference to `COMP_CTX_free'错误备忘
- 编译mtk的android工程,会出现如图所示的错误: undefined reference to “
- 解决新版GTK3编译时的错误: undefined reference to `gtk_init'
- 编译出现"undefined reference to `GTK_WIDGET_REALIZED',`GTK_WIDGET_VISIBLE' "相关错误的解决方法
- TORNADO下编译出现undefined reference to `itoa'错误