franneck94/Vscode-C-Cpp-Runner

[BUG] gcc not work in localpath, clang is working in localpath

Closed this issue · 8 comments

I've always used clang, so I don't know if the problem is a bug in the extension or vscode. A friend asked me to create an environment to use visual studio code configured with gcc to run without him needing to install gcc and visual studio code on his machine.

So I took the project I had with CLANG and just changed the executables to gcc and gdb and my return is always 1 and gcc doesn't seem to be working, follow in detail the configurations with clang working and gcc not working.

CONFIG Files Clang:
c_cpp_properties.json

{
  "configurations": [
    {
      "name": "windows-clang-x64",
      "includePath": [
        "${workspaceFolder}/**"
      ],
      "compilerPath": "${workspaceRoot}/msys64/ucrt64/bin/clang.exe",
      "cStandard": "${default}",
      "cppStandard": "${default}",
      "intelliSenseMode": "windows-clang-x64",
      "compilerArgs": [
        ""
      ]
    }
  ],
  "version": 4
}

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "C/C++ Runner: Debug Session",
      "type": "cppvsdbg",
      "request": "launch",
      "args": [],
      "stopAtEntry": false,
      "console": "externalTerminal",
      "cwd": "c:/Users/Utherbone/Documents/VSCODE/projetos",
      "program": "c:/Users/Utherbone/Documents/VSCODE/projetos/build/Release/outRelease"
    }
  ]
}

settings.json

{
  "C_Cpp_Runner.cCompilerPath": "${workspaceRoot}/msys64/ucrt64/bin/clang.exe",
  "C_Cpp_Runner.cppCompilerPath": "${workspaceRoot}/msys64/ucrt64/bin/clang++.exe",
  "C_Cpp_Runner.debuggerPath": "${workspaceRoot}/msys64/ucrt64/bin/lldb.exe",
  "C_Cpp_Runner.cStandard": "",
  "C_Cpp_Runner.cppStandard": "",
  "C_Cpp_Runner.msvcBatchPath": "",
  "C_Cpp_Runner.useMsvc": false,
  "C_Cpp_Runner.warnings": [
    "-Wall",
    "-Wextra",
    "-Wpedantic",
    "-Wshadow",
    "-Wformat=2",
    "-Wcast-align",
    "-Wconversion",
    "-Wsign-conversion",
    "-Wnull-dereference"
  ],
  "C_Cpp_Runner.msvcWarnings": [
    "/W4",
    "/permissive-",
    "/w14242",
    "/w14287",
    "/w14296",
    "/w14311",
    "/w14826",
    "/w44062",
    "/w44242",
    "/w14905",
    "/w14906",
    "/w14263",
    "/w44265",
    "/w14928"
  ],
  "C_Cpp_Runner.enableWarnings": true,
  "C_Cpp_Runner.warningsAsError": false,
  "C_Cpp_Runner.compilerArgs": [],
  "C_Cpp_Runner.linkerArgs": [],
  "C_Cpp_Runner.includePaths": [],
  "C_Cpp_Runner.includeSearch": [
    "*",
    "**/*"
  ],
  "C_Cpp_Runner.excludeSearch": [
    "**/build",
    "**/build/**",
    "**/.*",
    "**/.*/**",
    "**/.vscode",
    "**/.vscode/**"
  ],
  "C_Cpp_Runner.useAddressSanitizer": false,
  "C_Cpp_Runner.useUndefinedSanitizer": false,
  "C_Cpp_Runner.useLeakSanitizer": false,
  "C_Cpp_Runner.showCompilationTime": false,
  "C_Cpp_Runner.useLinkTimeOptimization": false,
  "C_Cpp_Runner.msvcSecureNoWarnings": false,
  "files.associations": {
    "stdio.h": "c"
  }
}

BUILD Clang

Executing task: C:/Windows/System32/cmd.exe /d /c C:\Users\Utherbone\Documents\VSCODE\projetos/msys64/ucrt64/bin/clang -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -O3 -DNDEBUG -c c:\Users\Utherbone\Documents\VSCODE\projetos\main.c -o .\build\Release\main.o && C:\Users\Utherbone\Documents\VSCODE\projetos/msys64/ucrt64/bin/clang -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -O3 -DNDEBUG   .\build\Release\main.o -o .\build\Release\outRelease.exe 

 *  Terminal will be reused by tasks, press any key to close it.

RUN Compiled by clang

Executing task: C:/Windows/System32/cmd.exe /d /c .\build\Release\outRelease.exe 

Hello 2023 *  Terminal will be reused by tasks, press any key to close it. 

<----------------------------------------------------------->

Now gcc configuration
c_cpp_properties.json

{
  "configurations": [
    {
      "name": "windows-gcc-x64",
      "includePath": [
        "${workspaceFolder}/**"
      ],
      "compilerPath": "${workspaceRoot}/msys64/ucrt64/bin/gcc.exe",
      "cStandard": "${default}",
      "cppStandard": "${default}",
      "intelliSenseMode": "windows-gcc-x64",
      "compilerArgs": [
        ""
      ]
    }
  ],
  "version": 4
}

launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "C/C++ Runner: Debug Session",
      "type": "cppdbg",
      "request": "launch",
      "args": [],
      "stopAtEntry": false,
      "externalConsole": true,
      "cwd": "c:/Users/Utherbone/Documents/VSCODE/projetos",
      "program": "c:/Users/Utherbone/Documents/VSCODE/projetos/build/Release/outRelease",
      "MIMode": "gdb",
      "miDebuggerPath": "${workspaceRoot}/msys64/ucrt64/bin/gdb.exe",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    }
  ]
}

settings.json

{
  "C_Cpp_Runner.cCompilerPath": "${workspaceRoot}/msys64/ucrt64/bin/gcc.exe",
  "C_Cpp_Runner.cppCompilerPath": "${workspaceRoot}/msys64/ucrt64/bin/g++.exe",
  "C_Cpp_Runner.debuggerPath": "${workspaceRoot}/msys64/ucrt64/bin/gdb.exe",
  "C_Cpp_Runner.cStandard": "",
  "C_Cpp_Runner.cppStandard": "",
  "C_Cpp_Runner.msvcBatchPath": "",
  "C_Cpp_Runner.useMsvc": false,
  "C_Cpp_Runner.warnings": [
    "-Wall",
    "-Wextra",
    "-Wpedantic",
    "-Wshadow",
    "-Wformat=2",
    "-Wcast-align",
    "-Wconversion",
    "-Wsign-conversion",
    "-Wnull-dereference"
  ],
  "C_Cpp_Runner.msvcWarnings": [
    "/W4",
    "/permissive-",
    "/w14242",
    "/w14287",
    "/w14296",
    "/w14311",
    "/w14826",
    "/w44062",
    "/w44242",
    "/w14905",
    "/w14906",
    "/w14263",
    "/w44265",
    "/w14928"
  ],
  "C_Cpp_Runner.enableWarnings": true,
  "C_Cpp_Runner.warningsAsError": false,
  "C_Cpp_Runner.compilerArgs": [],
  "C_Cpp_Runner.linkerArgs": [],
  "C_Cpp_Runner.includePaths": [],
  "C_Cpp_Runner.includeSearch": [
    "*",
    "**/*"
  ],
  "C_Cpp_Runner.excludeSearch": [
    "**/build",
    "**/build/**",
    "**/.*",
    "**/.*/**",
    "**/.vscode",
    "**/.vscode/**"
  ],
  "C_Cpp_Runner.useAddressSanitizer": false,
  "C_Cpp_Runner.useUndefinedSanitizer": false,
  "C_Cpp_Runner.useLeakSanitizer": false,
  "C_Cpp_Runner.showCompilationTime": false,
  "C_Cpp_Runner.useLinkTimeOptimization": false,
  "C_Cpp_Runner.msvcSecureNoWarnings": false,
  "files.associations": {
    "stdio.h": "c"
  }
}

BUILD Clang

Executing task: C:/Windows/System32/cmd.exe /d /c C:\Users\Utherbone\Documents\VSCODE\projetos/msys64/ucrt64/bin/gcc -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -O3 -DNDEBUG -c c:\Users\Utherbone\Documents\VSCODE\projetos\main.c -o .\build\Release\main.o && C:\Users\Utherbone\Documents\VSCODE\projetos/msys64/ucrt64/bin/gcc -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -O3 -DNDEBUG   .\build\Release\main.o -o .\build\Release\outRelease.exe 


 *  The terminal process "C:\Windows\System32\cmd.exe '/d', '/c', 'C:\Users\Utherbone\Documents\VSCODE\projetos/msys64/ucrt64/bin/gcc -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -O3 -DNDEBUG -c c:\Users\Utherbone\Documents\VSCODE\projetos\main.c -o .\build\Release\main.o && C:\Users\Utherbone\Documents\VSCODE\projetos/msys64/ucrt64/bin/gcc -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -O3 -DNDEBUG   .\build\Release\main.o -o .\build\Release\outRelease.exe'" terminated with exit code: 1. 
 *  Terminal will be reused by tasks, press any key to close it. 

RUN Compiled by clang
The executable is not yet built.

I'm using Msys2 and its folder is inside the working folder of the project opened in Visual Studio Code.

Have you verified that your GCC works in general?

What happens if you execute this by hand in the CMD?

C:\Users\Utherbone\Documents\VSCODE\projetos/msys64/ucrt64/bin/gcc -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -O3 -DNDEBUG -c c:\Users\Utherbone\Documents\VSCODE\projetos\main.c -o .\build\Release\main.o && C:\Users\Utherbone\Documents\VSCODE\projetos/msys64/ucrt64/bin/gcc -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -O3 -DNDEBUG .\build\Release\main.o -o .\build\Release\outRelease.exe

Haven't tested outside of Visual Studio Code or VSCodium

Have you verified that your GCC works in general?
Result in any path:

PS C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos> msys64\ucrt64\bin\gcc.exe
gcc.exe: fatal error: no input files
compilation terminated.
PS C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos> msys64\ucrt64\bin\gcc.exe main.c -o test.exe
PS C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos> ls


    Diretório: C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        05/10/2023     00:30                .vscode
d-----        05/10/2023     01:07                .vscode_clang
d-----        05/10/2023     01:07                .vscode_gcc
d-----        05/10/2023     00:42                build
d-----        05/10/2023     00:04                msys64
-a----        05/10/2023     04:27             93 main.c
-a----        05/10/2023     04:50         135221 main.exe


PS C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos>

Result in path parent of gcc executable:

PS C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos> cd msys64\ucrt64\bin\                                          
PS C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos\msys64\ucrt64\bin> ./gcc ../../../main.c -o testxx              
PS C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos\msys64\ucrt64\bin> ./testxx                       
Hello 2023 
PS C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos\msys64\ucrt64\bin> ls *txx.exe


    Diretório: C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos\msys64\ucrt64\bin


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        06/10/2023     01:06         133341 testxx.exe


PS C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos\msys64\ucrt64\bin> 

What happens if you execute this by hand in the CMD?

C:\Users\Utherbone\Documents\VSCODE\projetos/msys64/ucrt64/bin/gcc -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -O3 -DNDEBUG -c c:\Users\Utherbone\Documents\VSCODE\projetos\main.c -o .\build\Release\main.o && C:\Users\Utherbone\Documents\VSCODE\projetos/msys64/ucrt64/bin/gcc -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -O3 -DNDEBUG .\build\Release\main.o -o .\build\Release\outRelease.exe
Rsesult:

PS C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos> C:\Users\Utherbone\Documents\VSCODE\projetos/msys64/ucrt64/bin/gcc -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -O3 -DNDEBUG -c c:\Users\Utherbone\Documents\VSCODE\projetos\main.c -o .\build\Release\main.o && C:\Users\Utherbone\Documents\VSCODE\projetos/msys64/ucrt64/bin/gcc -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -O3 -DNDEBUG .\build\Release\main.o -o .\build\Release\outRelease.exe
No linha:1 caractere:270
+ ... Documents\VSCODE\projetos\main.c -o .\build\Release\main.o && C:\User ...
+                                                                ~~
O token '&&' não é um separador de instruções válido nesta versão.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidEndOfLine
 
PS C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos> 
PS C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos> C:\Users\Utherbone\Documents\VSCODE\projetos/msys64/ucrt64/bin/gcc -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -O3 -DNDEBUG -c c:\Users\Utherbone\Documents\VSCODE\projetos\main.c -o .\build\Release\main.o && C:\Users\Utherbone\Documents\VSCODE\projetos/msys64/ucrt64/bin/gcc -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -O3 -DNDEBUG .\build\Release\main.o -o .\build\Release\outRelease.exe
No linha:1 caractere:270
+ ... Documents\VSCODE\projetos\main.c -o .\build\Release\main.o && C:\User ...
+                                                                ~~
O token '&&' não é um separador de instruções válido nesta versão.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidEndOfLine
 
PS C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos> 

This is PowerShell and not CMD

CMD Test 1

C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos>C:\Users\Utherbone\Documents\VSCODE\projetos/msys64/ucrt64/bin/gcc -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -O3 -DNDEBUG -c c:\Users\Utherbone\Documents\VSCODE\projetos\main.c -o .\build\Release\main.o && C:\Users\Utherbone\Documents\VSCODE\projetos/msys64/ucrt64/bin/gcc -Wall -Wextra -Wpedantic -Wshadow -Wformat=2 -Wcast-align -Wconversion -Wsign-conversion -Wnull-dereference -O3 -DNDEBUG .\build\Release\main.o -o .\build\Release\outRelease.exe
O sistema não pode encontrar o caminho especificado.

C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos>

CMD Test 2

C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos>C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos\msys64\ucrt64\bin\gcc -c main.c -o teste.exe

C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos>dir
 O volume na unidade C não tem nome.
 O Número de Série do Volume é F0DB-33E0

 Pasta de C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos

06/10/2023  04:43    <DIR>          .
05/10/2023  00:16    <DIR>          ..
05/10/2023  00:30    <DIR>          .vscode
05/10/2023  01:07    <DIR>          .vscode_clang
05/10/2023  01:07    <DIR>          .vscode_gcc
05/10/2023  00:42    <DIR>          build
05/10/2023  04:27                93 main.c
05/10/2023  04:50           135.221 main.exe
05/10/2023  00:04    <DIR>          msys64
06/10/2023  04:43               168 NL891833388BR_.txt
               3 arquivo(s)        135.482 bytes
               7 pasta(s)   82.285.547.520 bytes disponíveis

C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos>

CMD Test 3
Result in path parent of gcc executable:

C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos>cd msys64\ucrt64\bin\

C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos\msys64\ucrt64\bin>./gcc ../../../main.c -o testxxT
'.' não é reconhecido como um comando interno
ou externo, um programa operável ou um arquivo em lotes.

C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos\msys64\ucrt64\bin>gcc ../../../main.c -o testxxT   

C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos\msys64\ucrt64\bin>dir  *estxxT.exe 
 O volume na unidade C não tem nome.
 O Número de Série do Volume é F0DB-33E0

 Pasta de C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos\msys64\ucrt64\bin

07/10/2023  03:43           133.341 testxxT.exe
               1 arquivo(s)        133.341 bytes
               0 pasta(s)   82.288.644.096 bytes disponíveis

C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos\msys64\ucrt64\bin>testxxT.exe       
Hello 2023 

C:\Users\Utherbone\Documents\VS_CODE_DEV\VSCODE_dev\projetos\msys64\ucrt64\bin>

What I noticed is that if I go to where GCC is using CMD, PS, ZSH (mysys2) it does not create an output, it compiles because it does not display any error, but it does not produce an output, if it is already executed while it is Inside its directory, when executed, it produces output.

That's very strange. I'm using Windows 11

Note, Clang works every way I've tried.

[UPDATED] I was sleeping through the keyboard and keyboard and keyboard and I ended up closing it and reopening it.

Sorry i dont really get your last comment.

So it works for absolute paths but not for relatives?

Ok, I apologize, I was in a hurry because I'm still studying at university, there are times when it's stressful.
had accidentally fallen asleep sitting in front of the computer and typing on keyboard in closing the issue

That's right, if I use direct or relative paths, it doesn't work, but if I open the windows shell CMD, PwerSehll, or any other and use the CD command in the directory where gcc is, it produces an output, does the build.

The strange thing is that otherwise it doesn't display any message

Now I'm reviewing it and what I wrote was really confusing. in the previous comment

Okay, then please only use absolute paths.