'How to use the OpenCV c++ with VSCODE
Base on this video https://www.youtube.com/watch?v=l4372qtZ4dc I am trying to use OpenCV in vscode but I canot include the, .lib files what should I do
main.cpp
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
I get this error
PS C:\Users\giorg\Documents\Development\Tests\node-addons-test\src\examples> g++ *.cpp main.cpp:1:33: fatal error: opencv2/core/core.hpp: No such file or directory #include ^ compilation terminated.
I manage to include the dlls but I can't find how I can include the files with .lib extension.
this is my c_cpp_properties.json file
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/src/lib",
"C:\\openCV\\opencv\\build\\include",
"C:\\openCV\\opencv\\build\\x64\\vc15\\lib" <=== this is the problem , how to include this
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17134.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}
Solution 1:[1]
Why not use cmake by adding a CMakeLists.txt, and it's also cross-platform and easy to use. I use VS Code, too. And I recommend to use cmake.
Solution 2:[2]
to include the .lib files you should acces the properties of your project =>linker=>entries=>additional dependencies then add your .lib fileproperties of project
Solution 3:[3]
When you are using CMake, it's not important what editor/IDE you are using. there are many ways to add an external library in CMake:
- using FindPackage
- using submodule
- using manually add the .h/.hpp and lib(dll/so/a/lib) files to your project
- and even more
one of the easiest method for adding an external lib to your project is submodule. just search about submodule and learn it, then you can easily use any library inside your project.
Here is a .cmake file that you can use it for submoduling easier https://www.scivision.dev/cmake-git-submodule/
and a tutorial on it here:
https://web.archive.org/web/20210703145609/https://github.blog/2016-02-01-working-with-submodules/
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Lee David |
Solution 2 | |
Solution 3 | SdSaati |