0

This is my tasks.json, why is build failing when I try to execute with GCC?

{
"version": "2.0.0",
"tasks": [
    {
        "type": "shell",
        "label": "C/C++: g++.exe build active file",
        "command": "C:\\MinGW\\bin\\g++.exe",
        "args": [
            "-g",
            "${file}",
            "-o",
            "${fileDirname}\\${fileBasenameNoExtension}.exe"
        ],
        "options": {
            "cwd": "C:\\MinGW\\bin"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }
]

}

This is the output when I type "gcc helloworld.exe" in terminal

> C:\Users\Administrator\projects\helloworld>gcc helloworld.exe
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: DWARF error: could not find abbrev number 3874
helloworld.exe:cygming-crtbegin.c:(.text+0x290): multiple definition of `_mingw32_init_mainargs'; c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../crt2.o:(.text+0x290): first defined here
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: helloworld.exe:cygming-crtbegin.c:(.text+0x2d0): multiple definition of `mainCRTStartup'; c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../crt2.o:(.text+0x2d0): first defined here
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: helloworld.exe:cygming-crtbegin.c:(.text+0x2f0): multiple definition of `WinMainCRTStartup'; c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../crt2.o:(.text+0x2f0): first defined here
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: helloworld.exe:cygming-crtbegin.c:(.text+0x310): multiple definition of `atexit'; c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../crt2.o:(.text+0x310): first defined here
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: helloworld.exe:cygming-crtbegin.c:(.text+0x320): multiple definition of `_onexit'; c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../crt2.o:(.text+0x320): first defined here
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: helloworld.exe:cygming-crtbegin.c:(.text+0x330): multiple definition of `__gcc_register_frame'; c:/mingw/bin/../lib/gcc/mingw32/9.2.0/crtbegin.o:cygming-crtbegin.c:(.text+0x0): first defined here
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: helloworld.exe:cygming-crtbegin.c:(.text+0x3e0): multiple definition of `__gcc_deregister_frame'; c:/mingw/bin/../lib/gcc/mingw32/9.2.0/crtbegin.o:cygming-crtbegin.c:(.text+0xb0): first defined here
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: helloworld.exe:cygming-crtbegin.c:(.bss+0x4): multiple definition of `_argc'; c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../crt2.o:(.bss+0x4): first defined here
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: helloworld.exe:cygming-crtbegin.c:(.bss+0x0): multiple definition of `_argv'; c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../crt2.o:(.bss+0x0): first defined here
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: helloworld.exe:cygming-crtbegin.c:(.eh_frame+0xc8): multiple definition of `__EH_FRAME_BEGIN__'; c:/mingw/bin/../lib/gcc/mingw32/9.2.0/crtbegin.o:cygming-crtbegin.c:(.eh_frame+0x0): first defined here
collect2.exe: error: ld returned 1 exit status

Solution is in the comments, thank you everyone for your help!

  • 4
    "I want to learn C and C+" C and C++ arent the most simple languages, I would not recomment to learn them at the same time, also because you'll only confuse yourself with things that appear to be same, but in fact are not – 463035818_is_not_an_ai Apr 19 '20 at 16:52
  • maybe this can help: https://stackoverflow.com/questions/172587/what-is-the-difference-between-g-and-gcc – 463035818_is_not_an_ai Apr 19 '20 at 16:54
  • 2
    Maybe try compiling from the command line first. – drescherjm Apr 19 '20 at 16:55
  • 1
    `gcc helloworld.exe`? Where are you specifying the source? Do you mean `gcc source.c -o helloworld.exe`? – David Ranieri Apr 19 '20 at 16:55
  • 1
    `I type "gcc helloworld.exe" in terminal` Why are you typing that? If you have an `helloworld.exe` you are done compiling. What you are attempting here is to compile and link the .exe into a second executable. This time compile the executable as a `c` program. – drescherjm Apr 19 '20 at 16:56
  • Maybe you wanted to type `gdb helloworld.exe` – drescherjm Apr 19 '20 at 17:13
  • the simplest solution is to NOT use json. Because .json is just another 'speed bump' that can be bypassed without any problem. – user3629249 Apr 20 '20 at 15:03

2 Answers2

1

To compile a C program, the command is

gcc -g -o helloworld.exe -Wall helloworld.c
  • -g Enable debugging

  • -o helloworld.exe Put the executable in helloworld.exe

  • -Wall Enable all warnings

  • helloworld.c Look for the source code in helloworld.c

Your command is attempting to "compile" the file which you expect the compiler to produce. I don't know if that is producing the errors you see, but it certainly is not correct.

rici
  • 234,347
  • 28
  • 237
  • 341
0

Okay I found somewhat of a solution.

I believe I was trying to compile again after already compiling it, when my intentions were to execute the file.

So I switched the code to c and compiled in the terminal with this:

gcc -g -o helloworld.exe -Wall hiworld.c

Then to execute the new exe I used this:

.\helloworld.exe

thanks for the help!