Windows编译OpenCV4Android解决undefined reference to std错误

OpenCV4Android支持三种使用方式
1.Java层调用
2.NDK调用动态库(方便,但是会包含整个.so库)
3.NDK调用静态库(灵活,比如没有用到机器学习模块,libopencv_ml.a里的代码是不会打包到动态库里的)
通过链接静态库的方式使用OpenCV4Android,CMAKE配置如下

#############################prepare for using of opencv static library####################
#first step to use opencv
set(OpenCV_STATIC ON)
#second step to use opencv
set(OpenCV_DIR C:/sdk/opencv-3.4.2-android-sdk/sdk/native/jni)
#third step to use opencv
find_package(OpenCV REQUIRED)
###########################################################################################
##################################################the native-lib shared library############
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
        native-lib

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        src/main/cpp/native-lib.cpp)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
        log-lib

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
        native-lib

        #foutth step to use opencv link opencv
        ${OpenCV_LIBS}
        # Links the target library to the log library
        # included in the NDK.
        ${log-lib})
######################################################################################

仅仅是新建项目稍稍修改了native-lib.cpp的代码,在函数里用了下opencv的函数

#include <jni.h>
#include <string>
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc_c.h"

extern "C" JNIEXPORT jstring JNICALL
Java_com_example_useprebuiltstaticlibrary_MainActivity_stringFromJNI(
        JNIEnv *env,
        jobject /* this */) {
    std::string hello="hello";
    cv::Mat m=cv::Mat::eye(3,3,CV_8UC1);
    return env->NewStringUTF(hello.c_str());
}

编译时却报错

Build command failed.
Error while executing process C:\sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build C:\sdk\demo\usePrebuiltStaticLibrary\app\.externalNativeBuild\cmake\debug\armeabi-v7a --target native-lib}
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
[2/2] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi-v7a\libnative-lib.so
FAILED: cmd.exe /C "cd . && C:\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe  --target=armv7-none-linux-androideabi23 --gcc-toolchain=C:/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 --sysroot=C:/sdk/ndk-bundle/sysroot -fPIC -isystem C:/sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -mfpu=neon -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -std=c++11 -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot C:/sdk/ndk-bundle/platforms/android-23/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--exclude-libs,libunwind.a -LC:/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\armeabi-v7a\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o  C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_highgui.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_features2d.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_shape.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_imgcodecs.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_ml.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_videoio.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_dnn.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_flann.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_objdetect.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_calib3d.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_video.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_superres.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_photo.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_imgproc.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_stitching.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_videostab.a -llog C:/sdk/opencv-3.4.2-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/liblibprotobuf.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_calib3d.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_features2d.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_highgui.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_videoio.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_imgcodecs.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/liblibjpeg-turbo.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/liblibwebp.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/liblibpng.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/liblibtiff.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/liblibjasper.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/libIlmImf.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_flann.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_video.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_photo.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_imgproc.a C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a -lz C:/sdk/opencv-3.4.2-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/libtbb.a -lc C:/sdk/opencv-3.4.2-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/libcpufeatures.a -ldl -lm -llog C:/sdk/opencv-3.4.2-android-sdk/sdk/native/3rdparty/libs/armeabi-v7a/libtegra_hal.a -latomic -lm "C:/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_static.a" "C:/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++abi.a" "C:/sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libunwind.a" "-ldl" && cd ."
C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) [clone .part.13]: error: undefined reference to ‘std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate)‘
C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::Exception::formatMessage(): error: undefined reference to ‘std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream(std::_Ios_Openmode)‘
C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::Exception::formatMessage(): error: undefined reference to ‘std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)‘
C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::Exception::formatMessage(): error: undefined reference to ‘std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)‘
C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::Exception::formatMessage(): error: undefined reference to ‘std::ostream::put(char)‘
C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::Exception::formatMessage(): error: undefined reference to ‘std::ostream::flush()‘
C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::Exception::formatMessage(): error: undefined reference to ‘std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)‘
C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::Exception::formatMessage(): error: undefined reference to ‘std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)‘
C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(system.cpp.o):system.cpp:function cv::Exception::formatMessage(): error: undefined reference to ‘std::ostream::put(char)‘.........C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(persistence_json.cpp.o):persistence_json.cpp:function icvJSONParseValue(CvFileStorage*, char*, CvFileNode*): error: undefined reference to ‘std::string::at(unsigned int)‘
C:/sdk/opencv-3.4.2-android-sdk/sdk/native/staticlibs/armeabi-v7a/libopencv_core.a(persistence.cpp.o):persistence.cpp:function check_if_write_struct_is_delayed(CvFileStorage*, bool): error: undefined reference to ‘std::string::assign(char const*, unsigned int)‘
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

google得知是因为编译这些静态库时所用的编译器、标准库等跟NDK当前的版本不同。网上的建议都是stl改为gnustl_static或gnustl_shared之类。可较新的NDK都不支持这些stl了,为了使用OpenCV静态库只能重新编译了。
编译OpenCV4Android的过程里爬了不少坑,总结一下,希望有助于小白们。

1. 安装MinGW
这里不详细的说了,网上很多教程。选择如图三项安装

安装好后差不多二三百兆,在环境变量Path里添加
C:\MinGW\bin
C:\MinGW\msys\1.0\bin
这里C:\MinGW是我的安装目录。配置好后需要注销计算机,再登陆。在命令行里gcc -v看到能输出版本就算差不多设置好环境了。

2. CMAKE 配置
下载好源代码解压,我放在C:\opencv-3.4.2。打开CMAKE图形界面

如图一定要选择MinGW Makefiles,我想这也是为什么一定要先安装配置MinGW的原因。选择指定工具链,点击next

这里一定要注意,选择的不是源代码
\opencv-3.4.2\platforms\android\android.toolchain.cmake
这个工具链,这个工具链过时了。新版本的NDK带有自己的工具链,这里选择NDK
/build/cmake/android.toolchain.cmake这个工具链。
这里感谢
https://github.com/opencv/opencv/issues/8742
点击Finish。有错误别管,点击configure。开始配置。出现错误就再点configure直到遇到一个跳不过去的错误,看看是不是让你配置SDK路径

Android SDK: specify path to Android SDK via ANDROID_SDK_ROOT /
  ANDROID_HOME / ANDROID_SDK variables

点击Add Entry添加变量

注意类型是FilePath。点击OK。点击configure。很快又跳出一个错误

CMake Error at cmake/android/android_gradle_projects.cmake:1 (message):

  Android gradle-based build/projects are not supported in this version of
  OpenCV.

  You need to downgrade Android SDK Tools to version 25.2.5.

  Details: https://github.com/opencv/opencv/issues/8460

Call Stack (most recent call first):
  cmake/android/OpenCVDetectAndroidSDK.cmake:204 (include)
  CMakeLists.txt:645 (include)

这是SDK比较新,新的SDK只支持Gradle编译,而OpenCV需要Ant编译。这里也给出了解决方法
Details: https://github.com/opencv/opencv/issues/8460
就是下载一个较旧的SDK。正如连接所说,windows选择这个
https://dl.google.com/android/repository/tools_r25.2.5-windows.zip
解压后发现里面只有一个tool目录,而SDK里也有一个tool目录。我的做法是先重命名SDK里的tool为tool28。再将下载的tool复制进SDK。
点击configure。(这里可能还是这个错误,这样就需要删除C:\opencv-3.4.2\build里所有内容,重启CMAKE。再来一次。所以这一步最好在CMAKE前就做好。
接下来会遇到这个错误

CMake Error at cmake/android/OpenCVDetectAndroidSDK.cmake:184 (message):
  Android SDK: Can‘t build Android projects as requested by
  BUILD_ANDROID_PROJECTS=ON variable.

  Use BUILD_ANDROID_PROJECTS=OFF to prepare Android project files without
  building them
Call Stack (most recent call first):
  CMakeLists.txt:645 (include)

如图搜索这个变量,取消选择。点击configure。
配置成功。

如图搜做tbb选择两项,否则不生成libtbb.a库,我不知这又什么用,但是预编译的SDK里有这个。
还有其它的一些变量可以配置,比如添加ANDROID_ABI,否则仅仅生成armeabi-v7a。修改变量、添加变量后记得configure。
配置完成点击generate,生成完成。CMAKE可关闭了。

3.编译
命令行进入C:\opencv-3.4.2\build目录,这里有很多配置好的文件,输入mingw32-make,就开始编译。等好久就成功了。

C:\opencv-3.4.2\build>mingw32-make
Scanning dependencies of target gen-pkgconfig
[  0%] Generate opencv.pc
[  0%] Built target gen-pkgconfig
Scanning dependencies of target libcpufeatures
[  0%] Building C object 3rdparty/cpufeatures/CMakeFiles/libcpufeatures.dir/cpu-features.c.o
[  0%] Linking C static library ..\lib\armeabi-v7a\libcpufeatures.a
[  0%] Built target libcpufeatures
Scanning dependencies of target libjpeg-turbo
[  0%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcapimin.c.o
[  1%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcapistd.c.o
[  1%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jccoefct.c.o
[  1%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jccolor.c.o
[  1%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcdctmgr.c.o
[  1%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jchuff.c.o
[  1%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcinit.c.o
[  1%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcmainct.c.o
[  1%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcmarker.c.o
[  1%] Building C object 3rdparty/libjpeg-turbo/CMakeFiles/libjpeg-turbo.dir/src/jcmaster.c.o
.
.
.
.
.
.
.
.
.
[ 99%] Linking CXX executable ..\..\bin\opencv_perf_stitching
[ 99%] Built target opencv_perf_stitching
Scanning dependencies of target opencv_videostab
[100%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab.dir/src/deblurring.cpp.o
[100%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab.dir/src/fast_marching.cpp.o
[100%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab.dir/src/frame_source.cpp.o
[100%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab.dir/src/global_motion.cpp.o
[100%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab.dir/src/inpainting.cpp.o
[100%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab.dir/src/log.cpp.o
[100%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab.dir/src/motion_stabilizing.cpp.o
[100%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab.dir/src/optical_flow.cpp.o
[100%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab.dir/src/outlier_rejection.cpp.o
[100%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab.dir/src/stabilizer.cpp.o
[100%] Building CXX object modules/videostab/CMakeFiles/opencv_videostab.dir/src/wobble_suppression.cpp.o
[100%] Linking CXX static library ..\..\lib\armeabi-v7a\libopencv_videostab.a
[100%] Built target opencv_videostab
Scanning dependencies of target opencv_test_videostab
[100%] Building CXX object modules/videostab/CMakeFiles/opencv_test_videostab.dir/test/test_main.cpp.o
[100%] Building CXX object modules/videostab/CMakeFiles/opencv_test_videostab.dir/test/test_motion_estimation.cpp.o
[100%] Linking CXX executable ..\..\bin\opencv_test_videostab
[100%] Built target opencv_test_videostab

4.配置库
生成的库在
\opencv-3.4.2\build\lib
第三方库在
\opencv-3.4.2\build\3rdparty\lib
将其复制到
\opencv-3.4.2-android-sdk
相应目录下替换掉原来的

现在编译项目则没有链接错误了。

参考文章:
1.https://github.com/opencv/opencv/issues/8742
2.https://github.com/opencv/opencv/issues/8460
3.https://blog.csdn.net/xiao19950820/article/details/77119891

原文地址:https://www.cnblogs.com/qq2523984508/p/9912221.html

时间: 2024-10-29 03:13:36

Windows编译OpenCV4Android解决undefined reference to std错误的相关文章

树莓派3B+实践(2)- 阿里云物联网平台接入(设备端C语言SDK编译)解决undefined reference to `IOT_CMP_Init&#39;错误

本想实践亚马逊aws的接入方案,由于亚马逊aws个人账户需要VISA信用卡,所以先用阿里云实践学习,以后有机会再接入aws. 1. 申请一个阿里云账户,需要绑定支付宝账户,阿里云个人账户可以申请部分业务免费,而且基础版每个月前100w条消息传输免费,个人用来学习实践绰绰有余. 2.根据阿里云物联网平台的帮助文档进行服务器端配置,这里不再赘述,帮助文档网址. 3. 重点说一下遇到的坑,由于阿里云的设备端sdk一直在更新功能,然而官网和github上的帮助文档没有随之更新,所以直接按照文档编译sdk

[ c++] cmake 编译时 undefined reference to `std::cout&#39; 错误的解决方案

cmake ..  和 make 之后,出现如下错误 Linking CXX executable ../../../bin/ModuleTest CMakeFiles/ModuleTest.dir/tmp.cpp.o: In function `main': /ModuleTest/tmp.cpp:4: undefined reference to `std::cout' tmp.cpp 内容如下 1 #include <iostream> 2 3 int main(){ 4 std::co

在codeblocks 下,C++编译不成功一直出现“undefined reference to `std::cout&#39;|

自己搞了好久才知道,编辑c++,要用g++ 希望对大家有帮助 在codeblocks 下,C++编译不成功一直出现"undefined reference to `std::cout'|

GCC编译uboot出现(.ARM.exidx+0x0): undefined reference to `__aeabi_unwind_cpp_pr0&#39;错误的解决办法

/opt/arm-2010.09/bin/../lib/gcc/arm-none-linux-gnueabi/4.5.1/armv4t/libgcc.a(_bswapsi2.o):(.ARM.exidx+0x0): undefined reference to `__aeabi_unwind_cpp_pr0' make: *** [u-boot] Error 1 一旦编译uboot出现上述错误,请不要慌张!解决办法官网已经给出,主要解决办法如下: vim 打开./lib_arm/eabi_com

ubuntu下 GCC编译程序出现 undefined reference to `std::ios_base::Init::Init()&#39;问题

网上的解释是:“ you need to add -lstdc++, or use 'g++' rather than 'gcc' as your driver program.”,也就是说如果想要使用g++编译程序的话,那么链接时需要添加“-Istdc++”. 我试了一下 , 在链接时加上"-Istdc++",就没有问题了. 关于g++,让我想起了,在ubuntu下一开始安装完code::blocks的时候,提示需要安装g++.原来code::blocks内置编译器使用的是g++,但

undefined reference to `std::__cxx11::basic_string&lt;char,

centos上编译报错,部分信息如下: /usr/local/lib/libprotobuf.so.9: undefined reference to `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::find_first_of(char, unsigned long) [email protected]_3.4.21' /usr/local/lib/lib

升级redis3.2.7编译报错“ undefined reference to `clock_gettime&#39;”

由于redis有个紧急的安全漏洞更新所以我升级线上的redis-cluster的版本.编译时报了一个错:" redis-3.2.7/deps/jemalloc/src/nstime.c:120: undefined reference to `clock_gettime' collect2: ld returned 1 exit status make[1]: *** [redis-server] Error 1 make[1]: Leaving directory `redis-3.2.7/s

undefined reference to `__gxx_personality_sj0&#39;错误解决办法

在交叉编译一个.cpp库时,出现如下错误: undefined reference to `__gxx_personality_sj0' undefined reference to `operator new[](unsigned int)' 解决办法: 修改库中的Makefile文件,在$(LD)  后面的选项中增加 -lsupc++ undefined reference to `__gxx_personality_sj0'错误解决办法

ubuntu下调试ffmpeg程序出现undefined reference to pthread_once ,undefined reference to uncompress错误

Ubuntu(版本16.04)下默认配置编译Ffmpeg(版本4.1.3configure 添加选项--enable-threads),将编译好的ffmpeg库添加到程序 中进行编译出现undefined reference to pthread_once ,undefined reference  to uncompress 等错误,提版本示pthread_once 未定义原因是编译链接时找不到pthread_one.解决的方法是安装pthread并将它链接到程序.具体安装的命令是: sudo