After days on working on this problem on my M1 studio, training to figure out, I got all these things correct on visual Code, but nothing worked, it will hang and never run; if I use Cmake, it will compile, but for debugging I could never get it to Run.
Meaning it will Run, but to will hang on my M1, everything worked fine, but could not debug code on MS Visual Code using OpenCV C++
Then I realized that I was trying to use Microsoft Software with Apple M1 and then installed XCODE, and everything worked great!!! And I love it!!!
And most important of all, I AM not using homeBrew!!!
1.- under "headers," I added /usr/local/include/opencv4
2.- under libraries, I added /usr/local/lib
3.- then I added the link libraries: libopencv_core.dylib, libopencv_imgproc.dylib, libopencv_highgui.dylib, libopencv_imgcodecs.dylib, libopencv_videoio.dylib.
So beautiful!!!! I was able to compile and debug my code, with break points and everything.
Here is my files for visual Code, for anyone:
tasks.json
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-fcolor-diagnostics",
"-fansi-escape-codes",
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"-I/usr/local/include/opencv4/**",
"-L/usr/local/lib",
"-lopencv_core",
"-lopencv_highgui",
"-lopencv_imgcodecs",
"${fileDirname}/${fileBasenameNoExtension}",
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
c_cpp_properties.jason
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/include/opencv4/**",
"/usr/local/lib"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-arm64"
}
],
"version": 4
}
Related
This question already has answers here:
How to avoid errors in Vscode for putting header files in a separate directory than src
(2 answers)
#include errors detected in vscode
(22 answers)
Closed 4 months ago.
I downloaded ncurses through msys64 then tried to include it in my source file as #include <ncurses.h>, then it didn't work so I tried changing the c_cpp_properties.json file
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\\msys64\\mingw64\\include",
"C:\\MinGW\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:\\MinGW\\bin\\g++.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}
the error persisted, what am I doing wrong
not sure what am I doing wrong, help is appreciated
i solved this problem in my vscode but i use linux, maybe this can be useful for you:
I inserted in the file "tasks.json", in the category args (cpp compiler argument) the option "** - I **", where I could define where my library is:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ compila il file attivo",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-I", //option of the compiler for set the library folder
"/usr/local/include/png++-0.2.10/", //patch to the library folder
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Attività generata dal debugger."
}
],
"version": "2.0.0"
}
this will probably help you
I am trying to use the openssl library for my C++ code.
I was able to configurate the include path correctly, but when I compile my program there is still a linker issue -> C:/Users/felix/my_future/PMS_Blockchain_CPP/pms_blockchain/src/Wallet.cpp:77: undefined reference to `EVP_PKEY_CTX_new_id'
collect2.exe: error: ld returned 1 exit status
I am using mingw64 inside visual studio code, my task.json looks like this:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${workspaceFolder}\\pms_blockchain\\src\\**.cpp",
"${workspaceFolder}\\openssl\\**.h",
"-o",
"${workspaceFolder}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
I think I have to add a new task for using the .lib files. I am not familiar with configurations like this, it already took me a lot of time to figure out how to create the existing task for compiling. I appreciate your help.
So with the help of drescherjm and his recommendation I was able to fix the issue. My problem was that I just made the configurations for using the header files in code, inside the c_cpp_properties.json file like this:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\\OpenSSL-Win64\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64",
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
}
But I didn't made the configuration for using the pre-build lib-files in the compiling process. Because the lib-files are containing the implementation for the header files, this is necessary. In the answer of the stackoverflow-link he provided, I was able to find the right commands to make the setup. Now my file is looking like this:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${workspaceFolder}\\pms_blockchain\\src\\**.cpp",
"-o",
"${workspaceFolder}\\${fileBasenameNoExtension}.exe",
"-L",
"${userHome}\\OpenSSL-Win64\\lib",
"-lssl",
"-lcrypto",
"${workspaceFolder}\\openssl\\**.h"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
I know this question been answered like a million time, and I have followed with each suggestion to no avail. I am trying to set up Eigen in my c++ code using VS code while running commands on Ubuntu 20.04 on windows. I was following with this specific post:
Post
This is my c_cpp_properties.cpp file:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/cygwin64/usr/include/**",
"C:/Program Files/LLVM/bin/**",
"C:/Users/J/Documents/eigen-3.4.0/eigen-3.4.0",
"C:/Users/J/Documents/eigen-3.4.0/eigen-3.4.0/Eigen/**",
"C:/Users/J/Documents/eigen-3.4.0/eigen-3.4.0/Eigen/src/**",
"C:/Users/J/Documents/eigen-3.4.0/eigen-3.4.0/test",
"C:/Users/J/Documents/eigen-3.4.0/eigen-3.4.0/test/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "\"C:/Program Files/LLVM/bin/clang++.exe\"",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
And following the suggestion from other posts, this is my tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I",
"C:\\Users\\J\\Documents\\eigen-3.4.0\\eigen-3.4.0\\Eigen\\",
],
"options": {
"cwd": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: \"C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe\""
}
]
}
Still getting the error:
Test.cpp:21:9: fatal error: Eigen/Dense: No such file or directory
21 | #include<Eigen/Dense>
| ^~~~~~~~~~~~~
compilation terminated.
I installed Eigen from: LINK
Any help is appreciated, thanks.
Although it seems unlikely, can you try adding a space between #include and <Eigen/Dense> and see if that works? The code probably doesn't compile when there's no space there, although in your case the compiler does recognise that you are trying to include something. Worth a shot.
what helped me is compiling my program with the following command line:
g++ -I /path/to/eigen/ my_program.cpp -o my_program
It's not efficient but there is a way around it I believe.
I have the opencv installed in /usr/include/opencv4 folder
I configured the VSCode as it should be, and the IntelliSense can detect the library.
The configuration should be correct (I guess)
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/opencv4/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
However, I get an error:
fatal error: opencv2/core.hpp: No such file or directory
2 | #include <opencv2/core.hpp>
| ^~~~~~~~~~~~~~~~~~
compilation terminated.
Am I missing something? Thanks
After a couple of days, I was able to find out the solution.
It was to add the necessary flags to the build task.
I posted the full sample on GitHub. Hopefully, it will help someone in the future.
The task.json should be
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"`pkg-config",
"--cflags",
"--libs",
"opencv4`"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/g++"
}
]
}
The missing was to add these arguments
"`pkg-config",
"--cflags",
"--libs",
"opencv4`"
I followed the tutorial on this webpage: https://code.visualstudio.com/docs/cpp/config-clang-mac to be able to compile c++ programs using VS Code. After doing all things requested, I am able to compile and to debug the c++ file.
However, it seems that there is an issue. In the box "PROBLEMS", I have the two following errors:
expected ';' at end of declaration [9, 23]
range-based for loop is a C++11 extension [-Wc++11-extensions] [11,
29]
My code is exactly the same as the one reported in the VS code website. I also checked all *.json files and c++17 is the default compiler.
The tasks.json is as follows:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
The c_cpp_properties.json is as follows:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
When compiling, everything is fine:
> Executing task: /usr/bin/clang++ -std=c++17 -stdlib=libc++ -g /Users/stephane/Documents/c++/causality/run_mainfile.cpp -o /Users/stephane/Documents/c++/causality/run_mainfile <
Terminal will be reused by tasks, press any key to close it.
Here is the screenshot:
I am using macOS 10.15.6, VS Code 1.47.1, and C/C++ extension v0.29.
Any ideas?
#RangerBob The solution is simply what #brc-dd said but you don't have to create a new project/directory. Go to Preferences > Search > "c++ standard". Choose C++17, and VS Code will create a new file "settings.json" with that standard causing the 3 warnings to disappear.