I am attempting to cross-compile some C/C++ programs I've written on Linux for Windows. I've had a lot of experience using both GCC and MSVC.
Normally when compiling a program using gcc, one would use the -l linker argument to specify a library to link against. It seems that this does not work properly when using the MingW-gcc linker.
GCC version:
i586-mingw32msvc-gcc (GCC) 4.4.4
When linking a program that uses (for example, GTK+ or libpng, libz, etc.), using something like:
i586-mingw32msvc-gcc -mwindows -L/opt/xcompile-win32/lib -lmylib -lmylib2 myprog.o -o myprog.exe
Gives numerous errors about undefined references to the library functions. However, if I specify the libraries as additional objects like this:
i586-mingw32msvc-gcc -mwindows -L/opt/xcompile-win32/lib /opt/xcompile-win32/lib/libmylib.a /opt/xcompile-win32/lib/libmylib2.a myprog.o -o myprog.exe
Everything works fine and the resulting program works great! My question is: Is there a way I can get the normal -l library arguments to work correctly? This method seems a bit cumbersome! I can't seem to find anything online which addresses this issue. Thanks!
Edit:
To clarify: the order of the library arguments on the command-line makes no difference. Also, the program compiles just fine on Linux (gcc) using only the -l arguments. Actual command below:
i586-mingw32msvc-gcc -mwindows -o win32/vmclient.exe win32/gtk_test.o \
-L/opt/xcompile-win32/lib -latk-1.0 -lpangoft2-1.0 -lpangocairo-1.0 \
-lgdk_pixbuf-2.0 -lm -lcairo -lpng12 -lpango-1.0 -lfreetype -lfontconfig \
-lgmodule-2.0 -lgthread-2.0 -lglib-2.0
win32/gtk_test.o:gtk_test.c:(.text+0x37): undefined reference to `_gtk_init_abi_check'
(and a bunch of similar errors). The program compiles fine for Win32 (using i586-mingw32msvc-gcc) when directly referencing the .a library files in the exact same order.