Closed sirus20x6 closed 4 years ago
The c_cpp_properties.json file is used to configure the C/C++ extension IntelliSense features and is not used for compiling. For clarification, the C/C++ extension does not provide compiling capabilities.
If you are using the VS Code tasks.json file to compile, then you'll need to add the include paths using the -I
include compiler option to the "args"
property in the tasks.json file. For example, see tutorial https://code.visualstudio.com/docs/cpp/config-mingw#_build-helloworldcpp
I ctrl+f that page for -I which did not appear. This is my tasks.json file
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++",
"command": "C:\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I c:/opencv/sources/modules/core/include/**"
],
"options": {
"cwd": "C:\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "C/C++: cpp.exe build active file",
"command": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\cpp.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I c:/opencv/sources/modules/core/include/**"
],
"options": {
"cwd": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
},
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I c:/opencv/sources/modules/core/include/**"
],
"options": {
"cwd": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin"
}
}
]
}
Sorry for confusion, I referred to https://code.visualstudio.com/docs/cpp/config-mingw#_build-helloworldcpp as example to show tasks.json.
As for adding include path option to the compiler args
property, I think the include path may need to be in a separate entry in the array, similar to how the output file is specified by "-o" and then the output file name is in the next entry in the array. Also, I don't know if **
for recursive includes is a feature that tasks.json knows.
So the args
may look something like:
"args": [
"-g",
"${file}",
"-I",
"c:\\opencv\\sources\\modules\\core\\include"
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
]
no change. still the same
Are you able to compile via the command line without using VS Code? Are you sure c:\\opencv\\sources\\modules\\core\\include
is the correct include path?
terminal
> Executing task: & 'C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\g++.exe' -g c:\code\opencvtest\main.cpp -I c:/opencv/sources/modules/core/include/ -o c:\code\opencvtest\main.exe <
In file included from c:/opencv/sources/modules/core/include/opencv2/core.hpp:54,
from c:/opencv/sources/modules/core/include/opencv2/core/core.hpp:48,
from c:\code\opencvtest\main.cpp:2:
c:/opencv/sources/modules/core/include/opencv2/core/base.hpp:52:10: fatal error: opencv2/opencv_modules.hpp: No such file or directory
#include "opencv2/opencv_modules.hpp"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
The terminal process terminated with exit code: 1
Terminal will be reused by tasks, press any key to close it.
screenshot of the files I'm trying to include https://i.imgur.com/si9eFh3.png
I guess it was supposed to be C:\opencv\build\include instead of .../sources/
my next issue is slightly different
> Executing task: & 'C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\g++.exe' -g c:\code\opencvtest\main.cpp -I C:\opencv\build\include -o c:\code\opencvtest\main.exe <
C:\Users\sirus\AppData\Local\Temp\ccB9qgVX.o: In function `main':
c:/code/opencvtest/main.cpp:10: undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
c:/code/opencvtest/main.cpp:10: undefined reference to `cv::operator-(cv::Mat const&, cv::Mat const&)'
c:/code/opencvtest/main.cpp:15: undefined reference to `cv::namedWindow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
c:/code/opencvtest/main.cpp:16: undefined reference to `cv::imshow(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, cv::_InputArray
const&)'
c:/code/opencvtest/main.cpp:17: undefined reference to `cv::waitKey(int)'
C:\Users\sirus\AppData\Local\Temp\ccB9qgVX.o: In function `ZN2cv3MatD1Ev':
C:/opencv/build/include/opencv2/core/mat.inl.hpp:754: undefined reference to `cv::fastFree(void*)'
C:\Users\sirus\AppData\Local\Temp\ccB9qgVX.o: In function `ZN2cv3Mat7releaseEv':
C:/opencv/build/include/opencv2/core/mat.inl.hpp:866: undefined reference to `cv::Mat::deallocate()'
collect2.exe: error: ld returned 1 exit status
The terminal process terminated with exit code: 1
Terminal will be reused by tasks, press any key to close it.
I'm not familiar with how to build OpenCV, but it sounds like you need to link to your OpenCV's libraries. I would refer to the OpenCV documentation and https://www.cs.swarthmore.edu/~newhall/unixhelp/howto_C_libraries.html .
Yes there were some differences between windows and linux that I was not aware of. I'm booted back in linux and can link, and build fine now.
c_cpp_properties.json
main.cpp
when trying to compile
`> Executing task: & 'C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin\g++.exe' -g c:\code\opencvtest\main.cpp -o c:\code\opencvtest\main.exe <
c:\code\opencvtest\main.cpp:2:10: fatal error: opencv2/core/core.hpp: No such file or directory
include <opencv2/core/core.hpp>
compilation terminated. The terminal process terminated with exit code: 1
Terminal will be reused by tasks, press any key to close it.
c:\code\opencvtest\main.cpp:2:10: fatal error: opencv2/core/core.hpp: No such file or directory
include <opencv2/core/core.hpp>
compilation terminated. The terminal process terminated with exit code: 1
Terminal will be reused by tasks, press any key to close it.
c:\code\opencvtest\main.cpp:2:10: fatal error: opencv2/core/core.hpp: No such file or directory
include "opencv2/core/core.hpp"
compilation terminated. The terminal process terminated with exit code: 1
Terminal will be reused by tasks, press any key to close it.
In file included from c:\code\opencvtest\main.cpp:2: c:/opencv/sources/modules/core/include/opencv2/core/core.hpp:48:10: fatal error: opencv2/core.hpp: No such file or directory
include "opencv2/core.hpp"
compilation terminated. The terminal process terminated with exit code: 1
Terminal will be reused by tasks, press any key to close it.`