I'm trying to build my C++ project in VSCode. However, I'm experiencing link issues with OpenCV "error LNK2001: unresolved external symbol". I've build all the libraries I use with vcpkg.
I build using this .bat file:
@echo off
if exist "C:Program Files (x86)Microsoft Visual Studio2019BuildToolsVCAuxiliaryBuildvcvarsall.bat" (
call "C:Program Files (x86)Microsoft Visual Studio2019BuildToolsVCAuxiliaryBuildvcvarsall.bat" x64
) else (
call "C:Program Files (x86)Microsoft Visual Studio2019CommunityVCAuxiliaryBuildvcvarsall.bat" x64
)
set compilerflags=/Od /Zi /EHsc /std:c++latest /I include /I C:includesvcpkginstalledx64-windowsinclude
set linkerflags=/OUT:binmain.exe
cl.exe %compilerflags% src*.cpp /link %linkerflags% /LIBPATH:C:includesvcpkginstalledx64-windowslib
del bin*.ilk *.obj *.pdb
My tasks.json file is:
{
"version": "2.0.0",
"tasks": [
{
"label": "Build C++ project",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"command": ".\build.bat"
},
{
"label": "Build & run C++ project",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
},
"command": ".\build.bat && .\bin\main.exe"
}
]
}
My launch.json file is:
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Debug (Windows)",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/main.exe",
"preLaunchTask": "Build C++ project",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
}
]
}
and finally my settings.json file is:
{
"terminal.integrated.shell.windows": "cmd.exe"
}
I can't seem to find any documentation on how to properly link vcpkg libraries with VSCode using the MSVS compiler. I would really appreciate some help.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…