Opencv、DSO缺失于命令行中 collect2:错误:ld返回1个退出状态。

7

我在Ubuntu 14.04上安装了OpenCV。我正在尝试按照OpenCV网站上的教程进行操作。但是在运行代码时出现了错误。我使用Eclipse来运行代码,而在构建项目时遇到了问题。我已经将opencv_core、opencv_highgui和opencv_imgcodecs库添加到g++链接器中。

Error message: 

//usr/local/lib/libopencv_imgproc.so.3.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make: *** [optest01] Error 1

代码:

#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <stdlib.h>
#include <stdio.h>

using namespace cv;

/// Global variables

Mat src, src_gray;
Mat dst, detected_edges;

/** @function main */
int main( int argc, char** argv )
{
  /// Load an image
  src = imread( "/images/Lenna.jpg" );

  if( !src.data )
  { return -1; }

  /// Create a matrix of the same type and size as src (for dst)
  dst.create( src.size(), src.type() );

  /// Convert the image to grayscale
  cvtColor( src, src_gray, COLOR_BGR2GRAY );

  return 0;
  }

2
你是否已经链接了 opencv_imgproc 库? - Miki
@Miki,谢谢你的回答,它有效。在教程中,我怎么知道要链接哪些库,因为它没有写明呢? - seleucia
  1. 根据错误信息逐个添加,直到它能够工作。
  2. 首先全部添加。
  3. 根据你的 #include 添加库。
  4. 一旦你了解 OpenCV 的工作原理,你就会知道该链接什么。
- Miki
@Miki 你应该将你的评论发布为这个问题的答案,这样seleucia就可以接受它了。 - NoChecksum
2个回答

18

您的错误代码:

//usr/local/lib/libopencv_imgproc.so.3.0: error adding symbols: DSO missing from command line

提示您没有链接opencv_imgproc库。 只需链接所需的库即可:

-lopencv_imgproc

2

我遇到了类似的问题,即命令行中缺少DSO,在前面添加-L/usr/local/lib解决了我的问题,例如:g++ source_code.cpp -o output_name -L/usr/local/lib <dependent libraries e.g. -lopencv_highgui>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接