3
votes

I am trying to compile a windows .c file on linux using the following command:

wine gcc.exe  x.c  -o x.exe -lws2_32

And I get this error.

C:/MinGW/bin/../lib/gcc/mingw32/3.4.5/../../../libmingw32.a(main.o):main.c:(.text+0x104): undefined reference to `WinMain@16'

However, when using gcc.exe with the -shared attribute, the error gone.

wine gcc.exe -shared x.c  -o x.exe -lws2_32

I tried viewing the help page of gcc.exe but can not find anything related to "-shared" argument

What does this argument do ?

2

2 Answers

2
votes

-shared will make a shared object from the code, rather than an executable.
An executable would need a main function as an entry point, hence the undefined reference error you saw. The shared object can be linked with other objects to make an executable.
See here or here

0
votes

You first line is actually almost correct. (Doctorlove told you that shared is for making shared objects, libraries, which is true.)

You have to add:

wine gcc.exe -mwindows x.c  -o x.exe -lws2_32

The -mwindows option is to tell GCC that you want to link a graphical Windows program, not a console program. Of course, your program must also contain a main() or WinMain() function, or you will get the same error message again.

As a side note, you may want to know that you don't have to use wine to cross compile with Mingw. There are mingw cross compilers for Linux. On Debian and Ubuntu you install it with apt-get install mingw32.