By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,277 Members | 1,200 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,277 IT Pros & Developers. It's quick & easy.

ERROR: "undefined reference to `_WinMain@16'" when compiling in Cygwin

P: 21
Hello there :)

I have been using Visual Studio on a program which I have just completed, however I need to have it compiling using a unix based compiler, when I try in cygwin, I get the following error:

undefined reference to `_WinMain@16'

I have tried searching for a workaround, although I am not a programming guru, and I find it difficult to comprehend the discussions on this topic :)

Any help is appreciated.
Sep 28 '07 #1
Share this Question
Share on Google+
16 Replies


Savage
Expert 100+
P: 1,764
Hello there :)

I have been using Visual Studio on a program which I have just completed, however I need to have it compiling using a unix based compiler, when I try in cygwin, I get the following error:

undefined reference to `_WinMain@16'

I have tried searching for a workaround, although I am not a programming guru, and I find it difficult to comprehend the discussions on this topic :)

Any help is appreciated.
Do you have WinMain in your project?

Savage
Sep 28 '07 #2

gpraghuram
Expert 100+
P: 1,275
Hello there :)

I have been using Visual Studio on a program which I have just completed, however I need to have it compiling using a unix based compiler, when I try in cygwin, I get the following error:

undefined reference to `_WinMain@16'

I have tried searching for a workaround, although I am not a programming guru, and I find it difficult to comprehend the discussions on this topic :)

Any help is appreciated.
Hi,
Does ur code have a main in it.
I think if u put a main it will be solved.
Thanks
Raghuram
Sep 28 '07 #3

P: 21
Hi,
Does ur code have a main in it.
I think if u put a main it will be solved.
Thanks
Raghuram
Thankyou for the replies.

yes it has a main function.
Sep 28 '07 #4

P: 21
The full error I am getting is:

/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libcygwin.a(libcmain.o):: undefined reference to `_WinMain@16'
collect2: ld returned 1 exit status
make: *** [nurseryTest] Error 1
Sep 28 '07 #5

weaknessforcats
Expert Mod 5K+
P: 9,197
You have created the wrong kind of project.

You have created a Windows application instead of a Console Application.

Do this:

1) Create a Win3e2 project
2) When the wizard appears DO NOT CLICK FINISH!
3) Instead, click Application Settings
4) Select Console Application and Empty Project
5) Now click finish

and off you go.
Sep 28 '07 #6

weaknessforcats
Expert Mod 5K+
P: 9,197
Egad! I didn't see you were using Cygwin.

You still have an incorrect project setup

But my instructions were for Visual Studio.

Sorry.
Sep 28 '07 #7

Savage
Expert 100+
P: 1,764
Hello there :)

I have been using Visual Studio on a program which I have just completed, however I need to have it compiling using a unix based compiler, when I try in cygwin, I get the following error:

undefined reference to `_WinMain@16'

I have tried searching for a workaround, although I am not a programming guru, and I find it difficult to comprehend the discussions on this topic :)

Any help is appreciated.
Is your cygwin compiler of Dev-C++?

Savage
Sep 28 '07 #8

P: 21
Is your cygwin compiler of Dev-C++?

Savage
I am unsure what you mean?

It is just the regular Cygwin that you get off the website...

Basically I need this program to compile in a unix environment
Sep 29 '07 #9

RRick
Expert 100+
P: 463
Try adding -mwindows to your gcc compiler command.

Take a look at this link http://www.ee.adfa.edu.au/staff/hrp/webDesignHelp/cygwin-ug-net-nochunks.html#OV-EX-WIN for more info. Refer to section 4.1.2
Sep 29 '07 #10

P: 21
Try adding -mwindows to your gcc compiler command.

Take a look at this link http://www.ee.adfa.edu.au/staff/hrp/webDesignHelp/cygwin-ug-net-nochunks.html#OV-EX-WIN for more info. Refer to section 4.1.2
I tried adding that command into my make file ( I think i did it right) but to no avail.

this is my make file:



Expand|Select|Wrap|Line Numbers
  1. all: nurseryTest
  2. all: nursery
  3. clean:
  4.     rm *.o nurseryTest
  5.     rm *.o nursery
  6.  
  7. nursery.o: nursery.cpp nursery.h
  8.     g++ -c nursery.cpp
  9.  
  10. nurseryTest.o: nursery.cpp nursery.h
  11.     g++ -c nurseryTest.cpp
  12.  
  13. nurseryTest: nurseryTest.o nursery.o
  14.     g++ -o nurseryTest.cpp nursery.o -o nurseryTest
  15.  
  16.  
As you see I have 3 files:

nursery.h
nurseryTest.cpp
nursery.cpp

I am not even sure if the makefile itself is correct, but I'm assuming it is because it creates the object files. When I add the gcc -mwindows line I get lots of errors, perhaps I am adding it wrong.

Cheers
Sep 30 '07 #11

RRick
Expert 100+
P: 463
Try adding the -mwindows to the g++ command. I would suggest also adding -Wall (turns on warnings). If you plan to debug the program using one of the GNU debuggers, then the following is useful (-g -O0) <--Oh-zero. These options are usually put just after the command and before the file information.

You will need the -mwindows option only for the command that makes the program. The other options are needed for all compilations.

The url link also used the program's resource file (xxx.res) during the linkage of the program. I'm not real familar with the .res file, but I know it is used for windows gui applications.
Sep 30 '07 #12

P: 1
I was receiving the same error, and I think it was due to having my main function in the wrong format.

I had originally had it formatted like this:

void Main()
{
}

When I changed the format to the following, the error went away:

main() {
}
Oct 23 '08 #13

Expert 10K+
P: 11,448
Main != main (C and C++ are case sensitive languages) and congrats for
resurrecting a thread that has been dead for almost 13 months.

kind regards,

Jos

ps. and make that 'int main()' as well if you don't want to look silly.
Oct 23 '08 #14

boxfish
Expert 100+
P: 469
I'm glad you fixed your error, but it doesn't have anything to do with where the braces are. However, I do approve of having the opening brace on the same line as the function name. main should be written like this:
Expand|Select|Wrap|Line Numbers
  1. int main() {
  2.     // Code here.
  3.     return 0;
  4. }
  5.  
Oct 23 '08 #15

100+
P: 110
Ah. Thread has been down for over 6 months?

C++ is case sensitive and must have been trying to use the Main() Function which I believe is a backwards WinMain() used back in the Windows 3.1 era, but not sure about that.

I would offer you to use MinGW if you are wishing to do c++ programming with an open source compiler. Cygwin has many problems that can happen with it. Though this is my opinion.

I'd use:
1. CodeBlocks (supersedes Dev-Cpp & cross OS compatable)
- This uses MinGW as opposed to cygwin
2. Visual Studio Express
3. CoLinux/AndLinux - use linux kernal/OS on top of windows

Oh well. Don't mind replying to a re-opened thread.
Oct 24 '08 #16

P: 1
Hi there.

I just got the same error in cygwin/gcc and found this thread. As noted the reason is that the "main" function with the proper signature was not supplied. I am using the following though, thanks anyway.

Expand|Select|Wrap|Line Numbers
  1. int main( int argc, char *argv[] )
  2. {
  3.     //...
  4.     return 0;
  5. }
  6.  
Jan 14 '12 #17

Post your reply

Sign in to post your reply or Sign up for a free account.