-1

I wanted to use vscode for c/c++. I installed gcc,gdb and g++. But when I ran a simple hello world code, it's showing error like this.

**C:/Users/aathi/Msys2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/aathi/Msys2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): in function `main':

C:/M/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain'

collect2.exe: error: ld returned 1 exit status**

The code I wrote is

#include<stdio.h>
int main(){
printf("Hello world");
return 0;
}

Pls tell me what to do abt this as I spend alot of time to get this instaled and setup only for this error to show up!

  • You need to look at how you build your program. You are using the wrong options for the compiler. (sorry but I don't know what the correct options are, but I'm sure you can google it). – john Aug 14 '22 at 18:12
  • 2
    U shld use either C or C++, not both. Beginners shld stick to a single language before mixing them. The C & C++ R distinct languages. 4 exmpl, C++ allows U 2 overload fn's & opr's; the C language doesn't. – Thomas Matthews Aug 14 '22 at 18:13
  • You should tell your IDE to use `gcc` for C programs and `g++` for C++ programs. Also, add the `-g` switch to generate debugging symbols. – Thomas Matthews Aug 14 '22 at 18:16

1 Answers1

0

You need to tell the compiler that you want to generate console application.

Use the compiler option -mconsole

0___________
  • 60,014
  • 4
  • 34
  • 74