静态OpenCV库中的未定义引用 [英] Undefined references in static OpenCV libraries

查看:756
本文介绍了静态OpenCV库中的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用OpenCV 3.1的C ++项目,并且使用共享库可以正常工作.但是现在我想使用静态库(位于项目目录中的文件夹中)对其进行编译,因为我希望能够在未安装OpenCV的情况下将其导出(并在必要时进行编辑和重新编译).

I have a project in C++ that uses OpenCV 3.1 and works fine using shared libaries. 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,将共享库设置为NO:

I have recompiled OpenCV this time setting shared libs to 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

并运行g++ a.cpp libopencv_core.a,其中a.cpp是用于测试是否一切正常的示例程序:

and ran g++ a.cpp libopencv_core.a where a.cpp is a sample program to test if everything works:

#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.

p.s. G ++和Ubuntu版本:g++ (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4

p.s. G++ and Ubuntu version: g++ (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4

推荐答案

您还需要链接pthread库.并将其作为-pthread

You need to link pthread library as well. And pass it as -pthread

g++ a.cpp libopencv_core.a -pthread

您缺少包含必需代码的其他库.必须有一个libippicv.a,其中包含ippicv*函数的代码

You're missing other libraries which contain the required code. There must be a libippicv.a which contains the code for ippicv* functions

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

它应该在第三方库中.

It should be somewhere among third_party libs.

这篇关于静态OpenCV库中的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆