Menu

WinMain function in a static library

2004-05-25
2012-09-26
  • Nobody/Anonymous

    I have a windows project that does not include a WinMain function.  WinMain is in a static library that is linked to the project. 

    When I link the program, I get an error for "Undefined reference to WinMain".  Is there a way to link leaving WinMain in the library?  Or will I have to include it in one of the main object modules?

     
    • aditsu

      aditsu - 2004-05-25

      if you define WinMain in a cpp file, it might be worth trying to declare it as extern "C"

      Adrian

       
    • Nobody/Anonymous

      I tried defining it as extern "C".  It did the same thing.

       
    • aditsu

      aditsu - 2004-05-25

      you're right, extern "C" has no effect, because WinMain is already declared as extern "C" in winbase.h
      however, it doesn't get linked to your program because it is not referenced
      to reference it, it is enough to write something like:

      void dummy(){WinMain(0,0,0,0);}

      somewhere in your main program files; you don't need to ever call the dummy function
      I think you could even make it inline and put it in a header file that you include

      Adrian

       
    • Nobody/Anonymous

      Check your linking order. Make sure you are linking with your WinMain containing lib before mingw tries to link in its runtime libs.

      Kip

       
    • Nobody/Anonymous

      The dummy function did it.

      Thanks.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.