I'm trying to compile a library in C++ for embedded projects using VS Code.
I have set up a few files and can compile the library without issue. The problem comes in with my include path.
My folder structure is:
root
|-.vscode
|-inc
| |-hal
| | |-esp32
| | | |-pin.h
| | | |-eeprom.h
|-src
| |-hal
| | |-esp32
| | | |-pin.cpp
| | | |-eeprom.cpp
When I include "pin.h" in "pin.cpp", I get an error when I include it directly. I need to include it via:
#include "./../../../inc/hal/esp32/pin.h"
In my c_cpp_properties.json file:
{
"configurations": [
{
"name": "esp32",
"includePath": [
"${workspaceFolder}/inc/hal/esp32/**",
"${workspaceFolder}/inc/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/Users/user/.espressif/tools/xtensa-esp32-elf/esp-2021r1-8.4.0/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc",
"cStandard": "c17",
"cppStandard": "c++98",
"intelliSenseMode": "macos-clang-arm64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
Is there another setting I'm missing that is causing this? From my understanding, I should be able to (at best) include "pin.h" directly or (at worst) "inc/hal/esp32/pin.h", but neither of these work.
Additional information:
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "espidf",
"name": "Launch",
"request": "launch"
}
]
}
settings.json:
{
"cmake.sourceDirectory": "${workspaceFolder}/.",
"C_Cpp.errorSquiggles": "Enabled"
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/clang++"
}
]
}
edit:
taks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/clang++"
}
]
}
Related
Every time i want to run my c++ code it show unable to debugging and not implemented.
please help to solve my problems
it seems error in launch.jsons / task.jsons / c_cpp_properties.jsons
please help me to resolve these error . I am new in coding and i am stuck in this from 4 days .
launch.jsons
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "C:\\Users\\Sumit\\Desktop\\vs code Projects\\CPP Projects\\hello_world.cpp",
"args": [],
"stopAtEntry": false,
"cwd": "C:\\MinGW\\bin",
"environment": [],
"console": "externalTerminal"
}
]
}
task.jsons
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:\\MinGW\\bin\\g++.exe"
}
]
}
c_cpp_properties.jsons
{
"configurations": [
{
"name": "Win32",
"includePath": [
"C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MinGW\\bin\\gcc.exe",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x86"
}
],
"version": 4
}
I plan to use opencv in vscode on macos.
I have configured my c_cpp_properties.json,launch.json and task.json
c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/Cellar/opencv/4.5.3_2/include/opencv4/**",
"/usr/local/Cellar/opencv/4.5.3_2/lib"
],
"defines": [],
"macFrameworkPath": [],
"compilerPath": "/usr/local/bin/gcc-11",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "macos-gcc-x64"
}
],
"version": 4
}
task.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ 生成活动文件",
"command": "/usr/bin/clang++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-I/usr/local/opt/opencv/include/opencv4",
"-L/usr/local/opt/opencv/lib",
"-lopencv_core"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
And the editor also has smart completion when I enter the include path
But I still get the file not found error, what should I do?
The issue I'm having is that when I run "C++ run/debug active file" the the code executes but doesn't stop at the breakpoints I set. I don't know a lot about how debuggers work but I'm guessing the the debugger isn't listening to the correct process? Or why would this happen?
In all honesty, I've been struggling to get all my dependencies correct and in the process may have broke intended functionality so it could be that I set up the scripts in a way that breaks it's intended use.
tasks.json looks like this:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "g++",
"args": [
"main.cc",
"-o",
"main",
"-std=c++17",
"-I/usr/local/include/cairomm-1.16",
"-I/usr/local/lib/cairomm-1.16/include",
"-I/usr/include/cairo",
"-I/usr/include/glib-2.0",
"-I/usr/lib/x86_64-linux-gnu/glib-2.0/include",
"-I/usr/include/pixman-1",
"-I/usr/include/uuid",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-I/usr/include/sigc++-3.0",
"-I/usr/lib/x86_64-linux-gnu/sigc++-3.0/include",
"-L/usr/local/lib",
"-lcairomm-1.16",
"-lcairo",
"-lsigc-3.0",
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: g++-9 build active file",
"command": "/usr/bin/g++-9",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-L/usr/local/lib",
"-lcairomm-1.16",
"-lcairo",
"-lsigc-3.0"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}
launch.json looks like this:
{
"version": "0.0.0",
"configurations": [
{
"name": "gcc - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc build active file",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
c_cpp_properties.json looks like this:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "g++",
"args": [
"main.cc",
"-o",
"main",
"-std=c++17",
"-I/usr/local/include/cairomm-1.16",
"-I/usr/local/lib/cairomm-1.16/include",
"-I/usr/include/cairo",
"-I/usr/include/glib-2.0",
"-I/usr/lib/x86_64-linux-gnu/glib-2.0/include",
"-I/usr/include/pixman-1",
"-I/usr/include/uuid",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-I/usr/include/sigc++-3.0",
"-I/usr/lib/x86_64-linux-gnu/sigc++-3.0/include",
"-L/usr/local/lib",
"-lcairomm-1.16",
"-lcairo",
"-lsigc-3.0",
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: g++-9 build active file",
"command": "/usr/bin/g++-9",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-L/usr/local/lib",
"-lcairomm-1.16",
"-lcairo",
"-lsigc-3.0"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}
I reworked it and went slower this time. I don't have a launch file but
Here's tasks:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-std=c++17",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-I/usr/local/include/cairomm-1.16",
"-I/usr/local/lib/cairomm-1.16/include",
"-I/usr/include/cairo",
"-I/usr/include/glib-2.0",
"-I/usr/lib/x86_64-linux-gnu/glib-2.0/include",
"-I/usr/include/pixman-1",
"-I/usr/include/uuid",
"-I/usr/include/freetype2",
"-I/usr/include/libpng16",
"-I/usr/include/sigc++-3.0",
"-I/usr/lib/x86_64-linux-gnu/sigc++-3.0/include",
"-L/usr/local/lib",
"-lcairomm-1.16",
"-lcairo",
"-lsigc-3.0",
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
And here's c_cpp_properties
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/lib",
"/usr/local/lib/cairomm-1.16/include",
"/usr/local/include/cairomm-1.16",
"/usr/include/sigc++-3.0",
"/usr/lib/x86_64-linux-gnu/sigc++-3.0/include",
"/usr/include/cairo",
"/usr/include/freetype2"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++20",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
I think there are a lot of unnecessary code in your tasks.json , try this out I am successfully able to set breakpoints during debugging .
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${workspaceFolder}\\*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:\\MinGW\\bin\\g++.exe"
}
]
}
I've been trying for several days to add a Path on VSCode to the 'boost' library I've installed for a practice I've got. I can't link up the code implementation with the library downloaded. It keeps printing on the Output: fatal error: boost/signals2/signal.hpp: No such file or directory. This is the c_cpp_properties.json I have:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/Program Files/boost/boost_1_66_0"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
In which I specify the route to 'boost' in 'includePath'. This is my tasks.json:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe compilar archivo activo",
"command": "C:\\w64devkit\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-lboost_system"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "Tarea generada por el depurador."
},
{
"type": "cppbuild",
"label": "C/C++: g++.exe compilar archivo activo ver(1)",
"command": "C:\\w64devkit\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-lboost_system"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Tarea generada por el depurador."
}
],
"version": "2.0.0"
}
And this is my code implementation:
#include <boost/signals2/signal.hpp>
#include <iostream>
using namespace std;
int main() {
cout << "Hello world" << endl;
return 0;
}
Very simple, but the problem is the linking from the compiler to the library. I don't know what to do
Link Project
https://github.com/nio74/templateGLad
Good day, I try Run Opengl app with glew and glad in Visual Studio Code(I wanted to use this Ide because it is multi platform but if you have any good suggestions it is welcome), but have this error:
> Executing task: C/C++: clang++ build active file <
Starting build...
Build finished with error:
Undefined symbols for architecture x86_64:
"_gladLoadGLLoader", referenced from:
_main in HelloWorld-22d65f.o
My tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-g",
"${workspaceFolder}/src/HelloWorld.cpp",
"-o",
"${workspaceFolder}",
"-I", "${workspaceFolder}/include/",
//"${workspaceFolder}/glad.c",
"-lglfw",
"-lglew"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/clang++"
}
]
}
Updating, doing various research I managed to make it work, but I have some things to understand:
I can't understand the variables in tasks.Json
(
"--include-directory = include /",
"--include-directory = build /",
"--include = include / glad.c",
)
I tried to replace them with those suggested by the official guide (
"$ {workspaceFolder} / include",
"$ {workspaceFolder} / build",
"$ {fileDirname} /include/glad.c",
)
but they don't work.
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "HelloWorld",
"type": "che",
"command": "clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-lglfw",
"-lglew",
"--include-directory=include/",
"--include-directory=build/",
"--include=include/glad.c",
//"${workspaceFolder}/include",
//"${workspaceFolder}/build",
//"${fileDirname}/include/glad.c",
"-framework",
"OpenGL",
"-framework",
"IOKit",
"-framework",
"Cocoa",
"src/helloworld.cpp",
"-o",
"build/helloworld",
"--debug"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
]
}
launch.json
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"preLaunchTask": "HelloWorld",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/helloworld",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
}
]
}
c_cpp_properties.json
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/src/",
"${workspaceFolder}/include/",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x86",
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"compilerArgs": [
"-lglfw",
"-lglew"
]
}
],
"version": 4
}
Git:
https://github.com/nio74/templateGLad