[Win32] Compiling C++ Code As A Library

Hey there,

I have been working on a WIN32 API library and recently tried to compile it (for the first time) using MINGW [G++] and I have come across a compiler error that I have been trying to track down for days now: undefined reference to 'WinMain@16'

My problem is that there should not be this dependency for an application entry point while I am trying to compile a library. And before anybody flags this as a 'non c++ related question' allow me to further explain:

While trying to pinpoint where this problem was coming from I had quite a number of people simply telling me to change the linkers subsystem but (as far as I am aware) this is a feature only available to VC++ user's. So, I am now beginning to wonder if it would be wise to enter the MINGW src and edit the entrypoint manually or if it would be easier to forward the WinMain call to another function like "MyLibraryMain"?

Any help would be appreciated and sorry for any lack of information, knowledge, etc as I am roughly (>12months) knew to WIN32. Thanks in advance guys :D
I believe there is a flag you can set :
-mwindows


To change the subsystem.
If you don't want the other little things thrown in with that (i.e. GDI and common dialogs), you can also use this instead to tell the linker to use the window subsystem rather than console:
-Wl,--subsystem,windows
Last edited on
There's also a -mdll option. I assume that's significant here.
Thanks for the help guys. So a few things I found.

-mwindows doesn't work in my case as it applies the windows subsystem causing the WinMain entry point to be called wheras I needed it not to be.

-Wl, --subsystem,windows is a viable option but I couldn't get it to work - is this a vc++ compiler option as oppose to MINGW?

-mdll worked perfectly. thanks kmn9 and to those wondering why it worked:
-mwindows is a g++ flag for applying the WINDOWS subsystem but this is not the system we want as it is the one that calls WinMain so by setting the system to DLL by using -mdll it bypasses the WinMain entry point and I have yet to do a full study but I can only assume it uses either the standard C main() or Win32 DLLMain()

Thanks again for your help guys,
Garry++

Topic archived. No new replies allowed.