2

When I am using SSE code with OpenCV libraries, I am getting an 'undefined reference'.

Ubuntu trusty (try on x86 and x86_64). Opencv libraries from apt-get.

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

int main()
{
  cv::VideoCapture cap("video.avi");

  if (cap.isOpened() == false)
    return 1;

  cv::Mat mat;
  cap >> mat;

  if (!mat.data)
    return 1;

  _mm_set1_ps(0.f);

  std::cout << "Done" << std::endl;
  return 0;
}


g++ `pkg-config --cflags --libs opencv` main.cpp -msse2

EDIT

main.cpp:(.text+0x42): undefined reference to cv::VideoCapture::VideoCapture(std::string const&)' main.cpp:(.text+0x66): undefined reference to cv::VideoCapture::isOpened() const' main.cpp:(.text+0x85): undefined reference to cv::VideoCapture::operator>>(cv::Mat&)' main.cpp:(.text+0xef): undefined reference to cv::VideoCapture::~VideoCapture()' main.cpp:(.text+0x111): undefined reference to cv::VideoCapture::~VideoCapture()' main.cpp:(.text+0x149): undefined reference to cv::VideoCapture::~VideoCapture()' /tmp/cc0yDKh1.o: In function cv::Mat::~Mat()': main.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x2b): undefined reference tocv::fastFree(void*)' /tmp/cc0yDKh1.o: In function cv::Mat::release()': main.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x3b): undefined reference tocv::Mat::deallocate()' collect2: error: ld returned 1 exit status

Can you help me to find the correct gcc command, please ?

Paul R
  • 208,748
  • 37
  • 389
  • 560
double_g
  • 836
  • 7
  • 9
  • 1
    See also: http://stackoverflow.com/questions/16192087/undefined-reference-to-initscr-ncurses/16192128#16192128 – Paul R Jan 25 '16 at 09:43

1 Answers1

0

In fact, it is not an SSE issue. When I change compilation command like this:

g++ -msse2 main.cpp `pkg-config --cflags --libs opencv`

It works, I don't know why ...

Paul R
  • 208,748
  • 37
  • 389
  • 560
double_g
  • 836
  • 7
  • 9