gpt4 book ai didi

c++ - 如何修复 'undefined reference' 错误 opencv 和 g++

转载 作者:行者123 更新时间:2023-11-28 01:17:21 30 4
gpt4 key购买 nike

我正在尝试在使用 OpenCV 的 VSCode 中构建简单的程序,已经阅读了堆栈中的数千篇文章,它们都是在 linux 上制作的(我尝试在 Windows 上制作)这是我的代码

这是我尝试使用的:

"args": [
"-g",
"-I",
"C:\\OpenCV\\opencv\\build\\include",
"${file}",
"-L",
"C:\\OpenCV\\opencv\\build\\x64\\vc15\\lib",
"-l",
"opencv_world345",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],

我检查了几次路径

#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
if ( argc != 2 )
{
printf("usage: DisplayImage.out <Image_Path>\n");
return -1;
}
Mat image;
image = imread( argv[1], 1 );
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}

这是我得到的结果

Executing task: C:\MinGW\bin\g++.exe -I C:\OpenCV\opencv\build\include >d:\programowanie\Projekt\Project\main.cpp -L >C:\OpenCV\opencv\build\x64\vc15\lib -l opencv_world345 -o >d:\programowanie\Projekt\Project\main.exe <

c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text+0x72):undefined reference to cv::imread(cv::String const&, int)'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text+0xe3): undefined reference to
cv::namedWindow(cv::String const&, int)' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text+0x129): >undefined reference to cv::imshow(cv::String const&, cv::_InputArray const&)'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text+0x149): >undefined reference to
cv::waitKey(int)' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text$_ZN2cv6StringC1EPKc[__ZN2cv6StringC1EPKc]+0x42): undefined reference to cv::String::allocate(unsigned int)'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text$_ZN2cv6StringD1Ev[__ZN2cv6StringD1Ev]+0xf): undefined reference to
cv::String::deallocate()' c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text$ZN2cv6StringaSERKS0[__ZN2cv6StringaSERKS0_]+0x1c): undefined reference to cv::String::deallocate()'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]+0x2d): undefined reference to
cv::fastFree(void*)'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text$_ZN2cv3Mat7releaseEv[__ZN2cv3Mat7releaseEv]+0x40): undefined reference to cv::Mat::deallocate()'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: >C:\Users\xxx\AppData\Local\Temp\ccXtHNOY.o:main.cpp:(.text$_ZN2cv3MataSEOS0_[__ZN2cv3MataSEOS0_]+0xb4): undefined reference to
cv::fastFree(void*)' collect2.exe: error: ld returned 1 exit status

我失去了理智,希望有人知道发生了什么

最佳答案

问题是您正在为 mingw 使用 Visual Studio 二进制文件。如果库是 c 库,这可能有效,但不适用于 opencv。以下站点具有用于 mingw 的非官方 opencv 二进制文件:https://github.com/huihut/OpenCV-MinGW-Build

关于c++ - 如何修复 'undefined reference' 错误 opencv 和 g++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58241091/

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