【问题标题】:Problems building OpenCV code on linux在 Linux 上构建 OpenCV 代码的问题
【发布时间】:2017-02-07 23:53:35
【问题描述】:

我最近一直在尝试正确配置 eclipse 以使用 OpenCV。将它安装到我的计算机后,(Ubuntu,使用 cmake)我尝试从 OpenCV 教程构建一些示例代码。 这是示例代码。

#include <cv.h>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <highgui.h>

using namespace cv;

int main( int argc, char** argv )
{
  Mat image;
  image = imread( argv[1], 1 );

  if( argc != 2 || !image.data )
    {
      printf( "No image data \n" );
      return -1;
    }

  namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
  imshow( "Display Image", image );

  waitKey(0);

  return 0;
}

添加了一些内容以使其正常工作。

一切都正确找到,但在构建时,出现这 3 个错误。 (我正在编译的文件名为test.cpp)

./test.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC    

make: *** [libOpenCV] Error 1   

recipe for target 'libOpenCV' failed

我不知道为什么会发生这些错误,或者如何解决它。有人知道吗?

【问题讨论】:

  • 好吧,错误信息告诉你该怎么做——用-fPIC标志重新编译你的代码。

标签: c++ linux opencv


【解决方案1】:

我认为你需要检查链接 obj,opencv 需要多个库才能正常工作。请查看 opencv 网站上的详细手册。

【讨论】:

    猜你喜欢
    • 2019-06-26
    • 2018-06-13
    • 2019-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-12
    • 1970-01-01
    相关资源
    最近更新 更多