Problem compilate with gcc & gdb on Vs code with windows - c

I’m starting with VScode and I can’t compile my programe corectement in C.
I’ve done a lot of research and I can’t find a solution. Can anyone help me?
C_CPP_Properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:\\MinGW\\include",
"C:\\MinGW\\lib\\gcc\\mingw32\\6.3.0\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
Launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Lancer",
"type": "cppdbg",
"request": "launch",
"program": "C:\\MinGW\\bin\\gcc.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Activer l'impression en mode Pretty pour gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Settings.json
{
"files.associations": {
"time.h": "c"
}
}
Task.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe générer le fichier actif",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe "
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"isDefault": true,
"kind": "build"
}
}
]
}
Main.c
#include<stdio.h>
#include<stdlib.h>
int main() {
int i = 1;
printf("Hello World\n");
return 0;
}
Error
PS C:\Dev\.git\Code> The program 'C:\MinGW\bin\gcc.exe' has exited with code 1 (0x00000001).
I’d really like to make it work,
I tried to manage on my own but I really didn’t find anything.
I hope the code I put in will be enough to maider.
Thx and have a good day :)

Related

Locate source files

I have C++ application in Visual Studio Code that uses function that is located in my shared library. I place shared library code in source directory and I can debug through it. I would like to place library source in other folder. But how to tell VS Code where this source is located.
Content of tasks.json
tasks": [
{
"type": "cppbuild",
"label": "linklib",
"command": "/usr/bin/gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-L", ".",
"-lmylib"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/gcc"
}
]
Content of launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "linklib"
//"preLaunchTask": "C/C++: build"
}
]
}

Value of miDebugger path is invalid in VS code while executing c program

Getting continuous error "unable to start debugging. The value of miDebuggerPath is invalid". while running a c program in VS Code
Here is launch.json file
{
"version": "0.2.0",
"configurations": [
{
"name": "g++ 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 gcc",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "g++ build active file",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe"
}
]
}
and here is tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
I tried to change the path of compiler but it's not working.

Issue with launching C program in VS Code. Probably something with the debugger

So, let me give a bit of an introduction first. I'm a 1st semester CS student and have C as a subject. My college recommends DevC++ but it doesn't run properly in my system so I tried using VS Code. My issue is that, in case of the program below, the output window pops up and then closes by itself. I have attached my code, launch.json, tasks.json, c_cpp_properties.json and the debug log as well below. Adding targetarchitecture in launch.json doesn't help.
I have also posted the same issue in github but while commenting my account was somehow flagged and so far, there haven't been any replies.
My code:
#include<stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
My launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe build and debug active file",
"type": "cppdbg",
"request": "launch",
"targetArchitecture": "x86_64",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"internalConsoleOptions": "openOnFirstSessionStart",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MingGW2\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"logging": {
"moduleLoad": true,
"programOutput": true,
"trace": true,
"traceResponse": true,
"engineLogging": true
},
},
]
}
My tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "gcc build & run active file",
"command": "C:\\MingGW2\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\MingGW2\\bin"
},
"problemMatcher":"$gcc",
"group": {
"kind": "build",
"isDefault": true
}
}
],
}
My c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\MingGW2\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x86"
}
],
"version": 4
}
The debug log is big and I'm quite sure it's repeating but, as I can't figure out any of it, I've included the whole log below.
The debug log

Get No such file or directory in Visual Studio Code when Debug with gcc

My C project need use MySQL, so there is code:
#include "mysql.h"
I just couldn't find out where should I add include path, or which key point I missed, I think I have get it done already. When I debug with (Windows)启动, it's works fine. But when I choose "gcc.exe", it always get "mysql.h: no such file or directory", please help!
I tried everything I can but still get this error.
this is my c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"C:/Program Files/MySQL/MySQL Server 8.0/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/Program Files/mingw64/bin/gcc.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
this is my launch.json:
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "gcc.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe build active file"
},
{
....................
},
]
}
this is my task.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe build active file",
"command": "C:\\Program Files\\mingw64\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-I",
"C:/Program Files/MySQL/MySQL Server 8.0/include",
"-L",
"C:/Program Files/MySQL/MySQL Server 8.0/lib",
"-llibmysql",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\Program Files\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: \"C:\\Program Files\\mingw64\\bin\\gcc.exe\""
}
]
}
The first thing I would try is hiding those spaces in your paths; terminal will read them as the end of an argument and start of a new one.
For example, in your launch.json, you have
"options": {
"cwd": "C:\\Program Files\\mingw64\\bin"
},
which I would try editing to
"options": {
"cwd": "C:\\\"Program Files\"\\mingw64\\bin"
},
Currently, terminal sees the path "C:\Program" and interprets "Files\mingw64\bin" as some weird argument that it probably just ignores. Your windows debugger may be smart enough to figure out that's wrong, but terminal operates pretty literally.
With "Program Files" contained in quotes (with escape chars), terminal should be able to read the whole path. Try that everywhere you have spaces in your paths and see if it helps.

Breakpoints are ignored in VS-Code debugging C with gdb

I try to debug my C-code but my breakpoints are ignored.
My system is Windows 10. VS-Code version is 1.38.
This is my launch.json entry:
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "C:/Users/NCH-Lap10/Desktop/aaa.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/TDM-GCC-64/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
},
I would appreciate any hints.
Could I provide more information?
Here I'm sharing my config files, just add them under .vscode folder, and also name the files as given below.
c_cpp_propreties.json
{
"configurations":[
{
"name":"Win32",
"includePath":[
"${workspaceFolder}/**",
"C:/MinGW/lib/gcc/mingw32/6.3.0/include/c++/trl"
],
"defines":[
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath":"C:\\MinGW\\bin\\gcc.exe",
"cStandard":"c11",
"cppStandard":"c++17",
"intelliSenseMode":"clang-x64"
}
],
"version":4
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:/MinGW/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "Compile C File"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile C File",
"command": "gcc",
"type": "shell",
"args": [
"-g",
"${file}",
"-o",
"${workspaceRoot}\\a.exe"
],
"problemMatcher": [
"$tsc"
],
"presentation": {
"reveal": "always"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
In order to work above configs, you need to have at least launch.json and tasks.json.
try to rebuild code
activate tabs with your code
press Ctrl+Shift + B
start debugging by pressing F5

Resources