#Undefined Reference WinMain

88 messages · Page 1 of 1 (latest)

willow root
#

So, I just started learning C++ and I wrote my first code in VS Code and when I wrote-
g++ .\01.cpp

Then it says- Undefined Reference WinMain

How do I fix it?

grim cobaltBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

willow root
#

Yupp

spiral owl
#

do control +s and recompile

willow root
#

Did not work

#

I tried this too

g++ 01.cpp -o 01.exe

spiral owl
#

just use visual studio community than. you probably installed the compiler incorrectly

#

visual studio community sets up the compiler for you

#

vscode forces you to install mingw64 and set it up yourself

willow root
#

I installed the compiler from WinLib

spiral owl
#

WinLib?

#

never heard

#

visual studio community just works \tm\

willow root
#

WinLibs

spiral owl
#

it has to be an issue with the compiler

willow root
#

So, how do I download the compiler correctly?

spiral owl
#

use visual studio community, it just works (tm)

willow root
#

Okieee

#

Thank youu

spiral owl
#

its what people tend to reccomend to new people

#

for good reason, it just works(tm)

willow root
#

!solved

grim cobaltBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

formal bramble
#

nooo A guy gets a basic error, and gets told to switch IDEs

formal bramble
spiral owl
#

if winMain isnt defined its an issue with the compiler, or int main isnt defined

#

maybe they are using a 32bit compiler in 64 bit system idk

willow root
#

I downloaded MinGW from WinLibs

#

MinGW-w64 GCC x86_64-posix-seh

#

This is the zip file

#

#include<iostream>
int main(){
std: : cout«"Hello";
return 0;
}

formal bramble
willow root
#

I have main in my code

spiral owl
#

posix?

cobalt plume
#

you are compiling your app as a windows application and not console application. Windows App require a different entry point

formal bramble
#

Can you screenshot your terminal, with the command you're running and the output you're getting?

spiral owl
#

win+shift+s is the shortcut for it

formal bramble
spiral owl
#

very useful

willow root
#

Ok wait!

willow root
formal bramble
#

Please don't clip your screenshots so much

willow root
#

What am I doing wrong?

formal bramble
#

Make the terminal wider and show the entire contents

#

Include the filename above the code in your screenshot

willow root
#

Okk

spiral owl
#

show what files are on the left

willow root
languid lotus
#

Make sure to save your file first.

willow root
#

I have saved

spiral owl
#

isn't circle on the file meaning he has not?

languid lotus
#

No, the white dot indicates that it's not.

spiral owl
#

ye click on the file and do control +S

#

vscode doesn't save by default

#

you have to do it manually

#

you can toggle autosave tho

formal bramble
willow root
#

I opened the folder with vs code then created the file

spiral owl
#

that doesn't save, its empty until you save

#

can you get on vc?

formal bramble
#

Press that and try compiling again

willow root
#

Okk

#

It worked 🤡

spiral owl
#

gotta toggle auto save

willow root
#

I thought VS code saves the file automatically

spiral owl
#

nahhh

#

that's like one of the first things you gotta toggle

willow root
#

Okkkk

spiral owl
#

i usually toggle it for windowChangeFocus

willow root
#

Thank you so much 😊

formal bramble
#

Also it stops being a problem when you start using tasks for compilation, or some other mechanism. Tasks autosave automatically

spiral owl
#

shi i called it first too, did say control+s as one of the first things

willow root
#

Sorry 😅

spiral owl
#

its ok lil bro

willow root
#

Thank you so muchh
Btw, can you give me some tips for learning cpp

spiral owl
#

do projects

#

define the problem, your inputs and than an algorithm

willow root
#

Okkk
We have Python in scl but I want to learn cpp 😅

spiral owl
#

programming is like telling someone instructions, except its like talking to someone who takes everything super literally