我是新來打開cv。目前我正在嘗試測試我是否可以運行一個簡單的文件。試圖編譯一個簡單的opencv C++文件
// Example showing how to read and write images
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv/cvaux.h>
int main(int argc, char** argv)
{
IplImage * pInpImg = 0;
// Load an image from file - change this based on your image name
pInpImg = cvLoadImage("bear.jpg", CV_LOAD_IMAGE_UNCHANGED);
if(!pInpImg)
{
fprintf(stderr, "failed to load input image\n");
return -1;
}
// Write the image to a file with a different name,
// using a different image format -- .png instead of .jpg
if(!cvSaveImage("my_image_copy.png", pInpImg))
{
fprintf(stderr, "failed to write image file\n");
}
// Remember to free image memory after using it!
cvReleaseImage(&pInpImg);
return 0;
}
我編譯它:
g++ `pkg-config –cflags opencv` cv.cpp -o cv `pkg-config –libs opencv`
我得到這個錯誤:
Undefined symbols for architecture x86_64:
"_cvLoadImage", referenced from:
_main in cv-zQ5X30.o
"_cvReleaseImage", referenced from:
_main in cv-zQ5X30.o
"_cvSaveImage", referenced from:
_main in cv-zQ5X30.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我丟在這裏,任何幫助將是非常讚賞。 謝謝。
你在Mac上? –
是的,我在MacOSX 10.8.5 – drifterOcean19
@ drifterOcean19嘗試編譯與-m32標誌添加。它看起來像你想編譯一個64位應用程序,並連接一個32位的OpenCV庫G ++'pkg配置-cflags opencv' cv.cpp -m32 -o CV'pkg配置-libs opencv' –