使用 OpenCV 库编译 SSE 代码

Compilation SSE code using OpenCV libraries

本文关键字:SSE 代码 编译 OpenCV 使用      更新时间:2023-10-16

当我将SSE代码与OpenCV库一起使用时,我得到了一个'未定义的引用'。

Ubuntu trusty (在 x86 和 x86_64 上尝试)。来自 apt-get 的 Opencv 库。

#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

编辑

main.cpp:(.text+0x42):未定义的引用 cv::VideoCapture::VideoCapture(std::string const&)' main.cpp:(.text+0x66): undefined reference to cv::VideoCapture::isOpened() const' main.cpp:(.text+0x85): undefined 引用cv::VideoCapture::operator>>(cv::Mat&)' main.cpp:(.text+0xef): undefined reference to cv::VideoCapture::~VideoCapture()' main.cpp:(.text+0x111): undefined 参考 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 to cv::fastFree(void*)'/tmp/cc0yDKh1.o: In function cv::Mat::release()': main.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x3b): undefined reference to cv::Mat::d eallocate()' collect2: error: ld 返回 1 个退出状态

你能帮我找到正确的 gcc 命令吗?

事实上,这不是 SSE 问题。当我像这样更改编译命令时:

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

它有效,我不知道为什么...