简体   繁体   English

静态OpenCV库中的未定义引用

[英]Undefined references in static OpenCV libraries

I have a project in C++ that uses OpenCV 3.1 and works fine using shared libaries. 我在C ++中有一个使用OpenCV 3.1的项目,并且使用共享库可以正常工作。 But now I want to compile it using static libraries (located in a folder within the project directory) because I want to be able to export it (and also edit and recompile if necessary) where OpenCV is not installed. 但是现在我想使用静态库(位于项目目录中的文件夹中)对其进行编译,因为我希望能够在未安装OpenCV的情况下将其导出(并在必要时进行编辑和重新编译)。

I have recompiled OpenCV this time setting shared libs to NO: 这次我重新编译了OpenCV,将共享库设置为NO:

make -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=NO -DCMAKE_INSTALL_PREFIX=~/Desktop/ocv ..

Then I took my required libraries: 然后,我获取了所需的库:

libopencv_core.a   libopencv_imgproc.a    libopencv_highgui.a
libopencv_video.a  libopencv_imgcodecs.a  libopencv_videoio.a

and ran g++ a.cpp libopencv_core.a where a.cpp is a sample program to test if everything works: 并运行g++ a.cpp libopencv_core.a ,其中a.cpp是用于测试是否一切正常的示例程序:

#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main()
{
    Mat a;
    printf("hello world\n" );
    return 0;
}

My problem is that I can not link the first library (core) because I get lots of undefined references like this: 我的问题是我无法链接第一个库(核心),因为我得到了很多这样的未定义引用:

libopencv_core.a(system.cpp.o): In function `cv::Mutex::Mutex()':
system.cpp:(.text._ZN2cv5MutexC2Ev+0x2c): undefined reference to `pthread_mutexattr_init'
system.cpp:(.text._ZN2cv5MutexC2Ev+0x39): undefined reference to `pthread_mutexattr_settype'
system.cpp:(.text._ZN2cv5MutexC2Ev+0x4c): undefined reference to `pthread_mutexattr_destroy'
libopencv_core.a(system.cpp.o): In function `cv::Mutex::trylock()':
system.cpp:(.text._ZN2cv5Mutex7trylockEv+0x8): undefined reference to `pthread_mutex_trylock'
libopencv_core.a(system.cpp.o): In function `cv::TlsAbstraction::TlsAbstraction()':
system.cpp:(.text._ZN2cv14TlsAbstractionC2Ev+0x9): undefined reference to `pthread_key_create'
libopencv_core.a(system.cpp.o): In function `cv::TlsAbstraction::~TlsAbstraction()':

and so on. 等等。 I have searched all over and cannot find what's missing. 我到处搜索,找不到丢失的内容。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

ps G++ and Ubuntu version: g++ (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4 ps G ++和Ubuntu版本: g++ (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4

You need to link pthread library as well. 您还需要链接pthread库。 And pass it as -pthread 并将其作为-pthread传递

g++ a.cpp libopencv_core.a -pthread

You're missing other libraries which contain the required code. 您缺少包含所需代码的其他库。 There must be a libippicv.a which contains the code for ippicv* functions 必须有一个libippicv.a ,其中包含ippicv*函数的代码

g++ a.cpp libopencv_core.a libippicv.a -pthread

It should be somewhere among third_party libs. 它应该在third_party库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM