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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Micko1
    New Member
    • Sep 2007
    • 21

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

    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.
  • Savage
    Recognized Expert Top Contributor
    • Feb 2007
    • 1759

    #2
    Originally posted by Micko1
    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

    Comment

    • gpraghuram
      Recognized Expert Top Contributor
      • Mar 2007
      • 1275

      #3
      Originally posted by Micko1
      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

      Comment

      • Micko1
        New Member
        • Sep 2007
        • 21

        #4
        Originally posted by gpraghuram
        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.

        Comment

        • Micko1
          New Member
          • Sep 2007
          • 21

          #5
          The full error I am getting is:

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

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            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.

            Comment

            • weaknessforcats
              Recognized Expert Expert
              • Mar 2007
              • 9214

              #7
              Egad! I didn't see you were using Cygwin.

              You still have an incorrect project setup

              But my instructions were for Visual Studio.

              Sorry.

              Comment

              • Savage
                Recognized Expert Top Contributor
                • Feb 2007
                • 1759

                #8
                Originally posted by Micko1
                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

                Comment

                • Micko1
                  New Member
                  • Sep 2007
                  • 21

                  #9
                  Originally posted by Savage
                  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

                  Comment

                  • RRick
                    Recognized Expert Contributor
                    • Feb 2007
                    • 463

                    #10
                    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#O V-EX-WIN for more info. Refer to section 4.1.2

                    Comment

                    • Micko1
                      New Member
                      • Sep 2007
                      • 21

                      #11
                      Originally posted by RRick
                      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#O V-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:



                      Code:
                      all: nurseryTest
                      all: nursery
                      clean:
                      	rm *.o nurseryTest
                      	rm *.o nursery
                      	
                      nursery.o: nursery.cpp nursery.h
                      	g++ -c nursery.cpp
                      
                      nurseryTest.o: nursery.cpp nursery.h
                      	g++ -c nurseryTest.cpp
                      	
                      nurseryTest: nurseryTest.o nursery.o
                      	g++ -o nurseryTest.cpp nursery.o -o nurseryTest
                      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

                      Comment

                      • RRick
                        Recognized Expert Contributor
                        • Feb 2007
                        • 463

                        #12
                        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.

                        Comment

                        • mseneta
                          New Member
                          • Oct 2008
                          • 1

                          #13
                          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() {
                          }

                          Comment

                          • JosAH
                            Recognized Expert MVP
                            • Mar 2007
                            • 11453

                            #14
                            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.

                            Comment

                            • boxfish
                              Recognized Expert Contributor
                              • Mar 2008
                              • 469

                              #15
                              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:
                              Code:
                              int main() {
                                  // Code here.
                                  return 0;
                              }

                              Comment

                              Working...