gpt4 book ai didi

c - OpenCV:尝试编译时出现 "Undefined symbols for architecture x86_64:"

转载 作者:太空宇宙 更新时间:2023-11-03 21:34:23 25 4
gpt4 key购买 nike

环境:操作系统:macOS,OpenCV:2.4.12

刚开始学习OpenCV,从书上记下一段代码,就是,

#include <opencv/highgui.h>

int main(int argc, char **argv) {
int iscolor = -1;
IplImage* img = cvLoadImage(argv[1], iscolor);
cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE);
cvShowImage("Example1", img);
cvWaitKey(0);

cvReleaseImage(&img);
cvDestroyWindow("Example1");
return 0;
}

当我尝试使用此命令编译此代码时 - gcc opencv1.c -o opencv1,它显示错误并显示以下消息。

Undefined symbols for architecture x86_64:
"_cvDestroyWindow", referenced from:
_main in opencv1-78cabd.o
"_cvLoadImage", referenced from:
_main in opencv1-78cabd.o
"_cvNamedWindow", referenced from:
_main in opencv1-78cabd.o
"_cvReleaseImage", referenced from:
_main in opencv1-78cabd.o
"_cvShowImage", referenced from:
_main in opencv1-78cabd.o
"_cvWaitKey", referenced from:
_main in opencv1-78cabd.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

有人知道解决办法吗?

最佳答案

编译时需要包含OpenCV库,pkg-config可以提供帮助:

gcc `pkg-config --cflags opencv` `pkg-config --libs opencv` opencv1.c -o opencv1

关于c - OpenCV:尝试编译时出现 "Undefined symbols for architecture x86_64:",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40148392/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com