我刚刚开始使用OpenCV,并且在this website上运行示例代码 .
我制作了一个 .cpp
文件并复制/粘贴了代码 .
我在命令行上运行以下命令:
g program.cpp -o program
我收到以下错误:
未定义引用
cv :: imread(cv :: String const&,int)'program.cpp :( . text 0x128):未定义引用
cv :: namedWindow(cv :: String const&,int)'program.cpp :( . text 0x17d):未定义引用cv :: imshow(cv :: String const&,cv :: _ InputArray const&)'program.cpp :( . text 0x1a5):未定义引用
cv :: waitKey(int) '/tmp/cceJEar6.o:在函数cv :: String :: String(char const *)':program.cpp :( . text._ZN2cv6StringC2EPKc [_ZN2cv6StringC5EPKc] 0x4d):对
cv :: String ::的未定义引用分配(unsigned long)'
它似乎是一个链接问题,它无法找到cv命名空间或opencv库
3 回答
编译时没有指定OpenCV库 . 使用此命令:
您必须将库文件指定为链接器标志 .
对于此特定程序,只需要OpenCV的 core 和 highgui 模块 . 随着程序中添加其他模块的功能,该列表将增加 .
然后编译
./run