Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » mingw: undefined reference to `WinMain@16'
mingw: undefined reference to `WinMain@16' [message #482026] Tue, 25 August 2009 07:36 Go to next message
Eclipse User
Originally posted by: outskywind.hotmail.com

I am new to eclipse cdt, i installed the mingw and the eclipse c/c++
ide as reccomended , and set the bin in path right . However, i can get
the toolchain configured with eclipse , when i am compiling an easy c++
project to check it out, i got the problem:
here is the c++ projet :
#include <iostream>
using namespace std;

int main(void) {
cout << "hello, word" << endl;
return 0;
}
and the error shows £ºC:\MinGW\lib/libmingw32.a(main.o):main.c: undefined
reference to `WinMain@16'.
how can i get rid of this problem? and anyone who have eclipse with mingw
worked successfully could give me a detail guide how to set them ? i would
appreciate it very much!
my email : outskywind@hotmail.com.
Re: mingw: undefined reference to `WinMain@16' [message #482049 is a reply to message #482026] Tue, 25 August 2009 09:07 Go to previous messageGo to next message
Dmitry Smirnov is currently offline Dmitry Smirnov
Messages: 90
Registered: July 2009
Member
What kind of project do you use?

I suppose, you should ensure that mingw is creating console program. Check with gcc/g++ options how to do this.
Re: mingw: undefined reference to `WinMain@16 ' [message #482134 is a reply to message #482049] Tue, 25 August 2009 13:24 Go to previous messageGo to next message
Eclipse User
Originally posted by: outskywind.hotmail.com

i see , but in eclipse c++ project menu , there are only two kinds :
makefile project and executable project... i choosed the makefile project.
and how should i set the gcc/g++ options right? thanks!
Re: mingw: undefined reference to `WinMain@16 ' [message #482202 is a reply to message #482134] Tue, 25 August 2009 16:57 Go to previous messageGo to next message
Dmitry Smirnov is currently offline Dmitry Smirnov
Messages: 90
Registered: July 2009
Member
This means that your project contains some makefile(s) that are processed by GNU make utility. Typically these files are called "Makefile" or have some extention like .mk.

Such file describe what and how to build. In this case you need to read make utility and mingw manuals.

Also you can try to get some help with
gcc --help
command.

it will tell you what options are supported by mingw GCC
Re: mingw: undefined reference to `WinMain@16 ' [message #482550 is a reply to message #482202] Thu, 27 August 2009 02:04 Go to previous messageGo to next message
Eclipse User
Originally posted by: outskywind.hotmail.com

i see that if i build the excutable c++ project , it will work well,and
it says " --library = mingw32 ". while when i build the makefile c++
project , i add that "creat makefile automatically" option.
in the objects.mk file the "LIBS := "is empty ,is this cause the error?
and someone says you should install Msys too if want to build makefile c++
project, is that ture ? and do you mean that i should write the makefile
myself?
Re: mingw: undefined reference to `WinMain@16 ' [message #482722 is a reply to message #482550] Thu, 27 August 2009 16:55 Go to previous messageGo to next message
Dmitry Smirnov is currently offline Dmitry Smirnov
Messages: 90
Registered: July 2009
Member
H-m, where did you find that "create makefile automatically"?

I meant, yes, you should create it by yourself. If there is some option to create it automatically, just try to add mingw32 to LIBS.

I'm not sure whether you need MSYS. If you have mingw, you most likely have all you need to build (i.e. make, gcc). Otherwise, you will get some error like "unable to run make" in Eclipse console.
Re: mingw: undefined reference to `WinMain@16 ' [message #482795 is a reply to message #482722] Fri, 28 August 2009 02:28 Go to previous messageGo to next message
Eclipse User
Originally posted by: outskywind.hotmail.com

Ah, in the properties menu,click the "c/c++ construction" mode , i see
"generate makefile" option.
yeah, i made the makefile myself,and it works :
CXXFLAGS = -O2 -g -Wall -fmessage-length=0

OBJS = say.o

LIBS =

TARGET = say.exe

$(TARGET): $(OBJS)
$(CXX) -o $(TARGET) $(OBJS) $(LIBS)

all: $(TARGET)

clean:
rm -f $(OBJS) $(TARGET)

and the eclipse console shows:
make all
g++ -O2 -g -Wall -fmessage-length=0 -c -o say.o say.cpp
g++ -o say.exe say.o

but,if i add "#pragma comment(linker, "/subsystem:console") " in my
sourcefile,without my makefile but using the"generate makefile
automatically" option,it works well too. so i have the idea there is
something missing in g++ link flags by default, and i saw someone add
"-Wl,-subsystem,console" as g++ link flag, what's that? and how could i
set the g++ link as console project,not win32 project.
thanks very much.
Re: mingw: undefined reference to `WinMain@16' [message #628930 is a reply to message #482026] Fri, 24 September 2010 18:46 Go to previous messageGo to next message
hoser is currently offline hoser
Messages: 1
Registered: September 2010
Junior Member
For anybody who finds this from a search, as I did: Another way to achieve this error is by not saving your file. The build system uses the version of the file on disk, not in the editor buffer. If the disk version of the file did not have a main function, then there is no place for the local application to start. If you get this error, make sure you saved your file.
Re: mingw: undefined reference to `WinMain@16' [message #649388 is a reply to message #628930] Wed, 19 January 2011 03:04 Go to previous messageGo to next message
No real name is currently offline No real name
Messages: 1
Registered: January 2011
Junior Member
Excelent response. This is the way to solve the problem. Thank you.
Re: mingw: undefined reference to `WinMain@16' [message #787058 is a reply to message #628930] Tue, 31 January 2012 05:15 Go to previous messageGo to next message
Faez Shingeri is currently offline Faez Shingeri
Messages: 2
Registered: January 2012
Junior Member
WAY to go Man..!!! TOOO GOOD... Smile

Struggled for two days with this prob... and finally simply saving the file was the SOLUTION..! Smile


Thanks alot
Re: mingw: undefined reference to `WinMain@16' [message #793149 is a reply to message #787058] Tue, 07 February 2012 20:38 Go to previous messageGo to next message
Ali Nematollahi is currently offline Ali Nematollahi
Messages: 1
Registered: February 2012
Junior Member
But sadly that doesn't help me Sad I save my file but I still get this error and I don't know how to get rid of it. Any ideas?
Re: mingw: undefined reference to `WinMain@16' [message #993732 is a reply to message #628930] Tue, 25 December 2012 09:23 Go to previous messageGo to next message
Alaa Albashar is currently offline Alaa Albashar
Messages: 1
Registered: December 2012
Junior Member
Thanx!!!
Exactly what I want Smile
Re: mingw: undefined reference to `WinMain@16' [message #998675 is a reply to message #628930] Thu, 10 January 2013 13:47 Go to previous messageGo to next message
Frederic Jeanmougin is currently offline Frederic Jeanmougin
Messages: 1
Registered: January 2013
Junior Member
It worked for me : I had this error because I forgot to save my "hello world" source file (because I was used to Visual C++ who do it automtically).
Re: mingw: undefined reference to `WinMain@16' [message #999094 is a reply to message #998675] Fri, 11 January 2013 10:27 Go to previous message
Axel Mueller is currently offline Axel Mueller
Messages: 1964
Registered: July 2009
Senior Member
Frederic Jeanmougin wrote on Thu, 10 January 2013 14:47
It worked for me : I had this error because I forgot to save my "hello world" source file (because I was used to Visual C++ who do it automtically).

In Preferences->General->Workspace you can enable "Save automatically before build".


Before you ask
- search this forum
- see the FAQ http://wiki.eclipse.org/CDT/User/FAQ
- google
Previous Topic:Correct parsing of for loop macros
Next Topic:MBS Custom launch configuration type filter
Goto Forum:
  


Current Time: Sat Oct 25 18:27:38 GMT 2014

Powered by FUDForum. Page generated in 0.10444 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software