opencv undefined我的库有问题吗?

时间:2014-07-11 07:17:50

标签: c++ opencv ubuntu codeblocks

我使用以下命令安装了opencv: git clone https://github.com/jayrambhia/Install-OpenCV.git

cd Install-OpenCV/
./dependencies.sh
./opencv_latest.sh

这给了我以下信息:

Package ffmpeg is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

确定这可能或不重要我进入了代码块并创建了一个默认的opencv模板项目。

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int main(int argc, char *argv[])
{
    Mat img = imread("lena.jpg", CV_LOAD_IMAGE_COLOR);
    if(img.empty())
       return -1;
    namedWindow( "lena", CV_WINDOW_AUTOSIZE );
    imshow("lena", img);
    waitKey(0);
    return 0;
}

这显示没有错误,但在编译时给了我以下错误:

AR: 9 undfined reference to 'cv::imread(std::string const&,int)'
AR: 12 undfined reference to 'cv::na(std::string const&,int)'
AR: 13 undfined reference to 'cv::InputArray::_InputArray(cv::Mat const&)'
AR: 13 undfined reference to 'cv::imshow(std::string const&, cv::InputArray(const&)'
AR: 14 undfined reference to 'cv::waitKey(int)'
usr/include/opencv... 278 undfined reference to 'cv::fastFree(void*)'
usr/include/opencv... 367 undfined reference to 'cv::Mat::deallocate()'

在sudo下运行getlatest而不是给了我以下的交换:

sudo ./opencv_latest.sh
... some normal looking stuff...
./opencv_latest.sh: 7: ./opencv_install.sh: [[: not found
./opencv_latest.sh: 11: ./opencv_install.sh: [[: not found
./opencv_latest.sh: 15: ./opencv_install.sh: [[: not found
--- Installing OpenCV 2.4.9
--- Installing Dependencies
./opencv_latest.sh: 27: ./opencv_install.sh: source: not found

尝试做他们在这里所做的事:http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html#linux-installation 给了我以下结果:

Prg1@KILLBOX:/usr/include/opencv2/release$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/include/opencv2
CMake Error: The source directory "/usr/include/opencv2/release/CMAKE_INSTALL_PREFIX=/usr/include/opencv2" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.

以下是我的链接器和编译器设置的选择: compiler linker

所以任何人都知道我在做什么,这是在ubuntu 14.04 LTS和codeblocks上

编辑: 使用ldconfig -p | grep opencv 给了我一大堆opencv文件,应该意味着它安装正确,对吗?那么链接器和编译器的问题呢?请注意,编译器设置(而不是搜索目录)中的链接器设置将opencv库显示为空,这是哪一个? 顺便说一下点击codeblocks中的错误消息(opencv lib中的一次)实际上确实会打开opencv lib的片段,看起来像是在那个位置的正确代码行(因为它们包含日志的功能)显示为缺失)

1 个答案:

答案 0 :(得分:1)

从git下载源代码后,您是否正确构建了OpenCv 请查看此链接: - http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html

未定义的引用错误意味着链接器无法找到您在项目中使用的函数的代码,因此您需要首先正确安装opencv。