2

Hello i am very new to visual studios and c++, but i have tried multiple different ways of trying to install it by multiple different tutorials and none seem to work, i must be doing something wrong.

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

I am just trying to run a simple hello world command but get this error

[Running] cd "c:\AdamWilson\Code\Languages\C++\MightWork\" && gcc pleasework.c -o pleasework && "c:\AdamWilson\Code\Languages\C++\MightWork\"pleasework
C:/AdamWilson/Code/Languages/C++/mingw32/bin/../lib/gcc/i686-w64-mingw32/8.1.0/../../../../i686-w64-mingw32/lib/../lib/libmingw32.a(lib32_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x39): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154
Adam Wilson
  • 31
  • 1
  • 7
  • I assume you mean Visual Studio Code. This is not the microsoft compiler – drescherjm Jun 01 '20 at 19:18
  • If this is Visual Studio Code you probably want to tag for that and show your tasks.json file. – drescherjm Jun 01 '20 at 19:19
  • 3
    `undefined reference to `WinMain@16` you are creating a windows gui application not a console one. – drescherjm Jun 01 '20 at 19:20
  • 1
    This should help: https://stackoverflow.com/questions/5259714/undefined-reference-to-winmain16 – drescherjm Jun 01 '20 at 19:21
  • 3
    You tag the question with c and c++, you are saying you are new in c++, your code is c, the file extraction is c, you use gcc, the c compiler. Are you sure you're studying c++? – 273K Jun 01 '20 at 19:43
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Mgetz Feb 09 '23 at 14:27

1 Answers1

-1

I tried your program with the following command(this can be seen in the error message):

gcc pleasework.c -o pleasework

And it worked

I searched further for the answer and found that if I give an empty file to gcc. Then I get the following error message:

undefined reference to `WinMain@16'

So maybe you got the error because you forgot to save the code file and gcc only found the empty file.

This information is from the Position is everything site.

I hope this helps to solve your problem.

RBL12C
  • 5
  • 5
  • [A code-only answer is not high quality](//meta.stackoverflow.com/questions/392712/explaining-entirely-code-based-answers). While this code may be useful, you can improve it by saying why it works, how it works, when it should be used, and what its limitations are. Please [edit] your answer to include explanation and link to relevant documentation. – Stephen Ostermiller Feb 09 '23 at 10:37