提问人:Muhammad Ikhwan Perwira 提问时间:6/24/2022 最后编辑:Christoph RackwitzMuhammad Ikhwan Perwira 更新时间:6/24/2022 访问量:950
致命错误LNK1120:5 个未解决的外部问题
fatal error LNK1120: 5 unresolved externals
问:
我正在运行 c++ 简单的 opencv 程序,它给了我这样的错误
Starting build...
cl.exe /Zi /EHsc /nologo /FeC:\Users\User\Documents\KULIAH\LAB_SOFTWARE\Program_C\belajar_syntax\halo.exe C:\Users\User\Documents\KULIAH\LAB_SOFTWARE\Program_C\belajar_syntax\halo.cpp -I C:\opencv\build\include /link /LIBPATH:C:\opencv\build\x64\vc15\lib
halo.cpp
halo.obj : error LNK2019: unresolved external symbol "public: __thiscall cv::Mat::Mat(int,int,int,class cv::Scalar_<double> const &)" (??0Mat@cv@@QAE@HHHABV?$Scalar_@N@1@@Z) referenced in function _main
halo.obj : error LNK2019: unresolved external symbol "public: __thiscall cv::Mat::~Mat(void)" (??1Mat@cv@@QAE@XZ) referenced in function _main
halo.obj : error LNK2019: unresolved external symbol "void __cdecl cv::destroyAllWindows(void)" (?destroyAllWindows@cv@@YAXXZ) referenced in function _main
halo.obj : error LNK2019: unresolved external symbol "int __cdecl cv::waitKey(int)" (?waitKey@cv@@YAHH@Z) referenced in function _main
halo.obj : error LNK2019: unresolved external symbol "void __cdecl cv::imshow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::_InputArray const &)" (?imshow@cv@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV_InputArray@1@@Z) referenced in function _main
C:\Users\User\Documents\KULIAH\LAB_SOFTWARE\Program_C\belajar_syntax\halo.exe : fatal error LNK1120: 5 unresolved externals
Build finished with error(s).
The terminal process terminated with exit code: -1.
Terminal will be reused by tasks, press any key to close it.
> Executing task: C/C++: cl.exe build active file <
Starting build...
cl.exe /Zi /EHsc /nologo /FeC:\Users\User\Documents\KULIAH\LAB_SOFTWARE\Program_C\belajar_syntax\halo.exe C:\Users\User\Documents\KULIAH\LAB_SOFTWARE\Program_C\belajar_syntax\halo.cpp -I C:\opencv\build\include /link /LIBPATH:C:\opencv\build\x64\vc15\lib\**
halo.cpp
halo.obj : error LNK2019: unresolved external symbol "public: __thiscall cv::Mat::Mat(int,int,int,class cv::Scalar_<double> const &)" (??0Mat@cv@@QAE@HHHABV?$Scalar_@N@1@@Z) referenced in function _main
halo.obj : error LNK2019: unresolved external symbol "public: __thiscall cv::Mat::~Mat(void)" (??1Mat@cv@@QAE@XZ) referenced in function _main
halo.obj : error LNK2019: unresolved external symbol "void __cdecl cv::destroyAllWindows(void)" (?destroyAllWindows@cv@@YAXXZ) referenced in function _main
halo.obj : error LNK2019: unresolved external symbol "int __cdecl cv::waitKey(int)" (?waitKey@cv@@YAHH@Z) referenced in function _main
halo.obj : error LNK2019: unresolved external symbol "void __cdecl cv::imshow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::_InputArray const &)" (?imshow@cv@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV_InputArray@1@@Z) referenced in function _main
C:\Users\User\Documents\KULIAH\LAB_SOFTWARE\Program_C\belajar_syntax\halo.exe : fatal error LNK1120: 5 unresolved externals
我怀疑这是因为库链接器问题,这是我的tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: cl.exe build active file",
"command": "cl.exe",
"args": [
"/Zi",
"/EHsc",
"/nologo",
"/Fe${fileDirname}\\${fileBasenameNoExtension}.exe",
"${file}",
"-I",
"C:\\opencv\\build\\include",
"/link",
"/LIBPATH:C:\\opencv\\build\\x64\\vc15\\lib\\"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
这是我运行的代码
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main() {
// Create blue image
Mat blueImage(10, 10, CV_8UC1, Scalar(0, 0, 255));
// Display the image.
imshow("grayscale image", blueImage);
// Wait for a keystroke.
waitKey(0);
// Destroys all the windows created
destroyAllWindows();
return 0;
}
根据我用来编译程序。tasks.json
cl.exe
在我从 python 转向学习 opencv 后,我是 C++ 环境的新手,因为我听说 C++ 很快。就像我说的,我有链接并包含在参数中。但仍然有错误。cl.exe
我也尝试更改仍然给我错误。vc15
vc14
我没有从源代码安装 opencv,但我从发布官方网站下载了名称opencv-4.6.0-vc14_vc15.exe
答: 暂无答案
评论
/link
cl.exe