Edgar Crockett
Edgar Crockett

Reputation: 55

make recipe to link to avoid undefined reference to WinMain@16

Thanks for taking my question. I have spent many hours checking posts on this but I still need help. Thanks for being patient with me :)

I have a class of midi functions that calls the Widows multimedia API.

When I compile my class Midf.h by itself at the command line it compiles and works:

g++ -Wall Midf.h Midf.cpp midftest.cpp -lwinmm -o midftest2.exe

I have written a makefile to include these functions in a larger program.

My recipe for building the Midf.o is as follows:

 Midf.o: Midf.cpp Midf.h
              g++ -Wall Midf.cpp -lwinmm

At this point I get the following error:

g++ -Wall Midf.cpp -lwinmm
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/libmingw32.a(main.o): In function `main':
e:\p\giaw\src\pkg\mingwrt-4.0.3-1-mingw32-src\bld/../mingwrt-4.0.3-1-mingw32-src/src/libcrt/crt/main.c:91: undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
Makefile:21: recipe for target 'Midf.o' failed
make: *** [Midf.o] Error 1

I have read that Mingw does not support wmain, but there is a way around that by making sure that main is defined properly outside of a namespace. I am not sure how to do that.

I would be glad to post the entire makefile, my file that contains main(), Midf.h Midf.cpp or any other file in the source code to find the problem.

By the way, this is a console program and I have tried building it with MinGW and with Cygwin.

Thanks again for everyone willing to help!

Upvotes: 1

Views: 2680

Answers (1)

user657267
user657267

Reputation: 20990

To turn my comments into an answer:

If you want to perform separate compilation you have to tell gcc not to link your objects by passing the -c flag.

Your second problem was not passing the libraries during linking, passing them during compilation has no effect.

Upvotes: 2

Related Questions