2016-01-25 138 views
2

當我在OpenCV庫中使用SSE代碼時,出現'未定義的引用'。編譯使用OpenCV庫的SSE代碼

Ubuntu可信賴(試用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): 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 to cv::fastFree(void*)' /tmp/cc0yDKh1.o: In function cv::Mat::release()': main.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x3b): undefined reference to cv::Mat::deallocate()' collect2: error: ld returned 1 exit status

你能幫我找到正確的海灣合作委員會的命令,好嗎?

+1

參見:http://stackoverflow.com/questions/16192087/undefined-reference-to -initscr-ncurses/16192128#16192128 –

回答

0

事實上,這不是SSE問題。當我改變編譯命令是這樣的:

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

它的工作原理,我不知道爲什麼......

+0

可能是因爲庫需要在main.cpp之後。 –