Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Glooper on October 28, 2011, 05:16:09 pm

Title: Using Code::Blocks to make DirectX program
Post by: Glooper on October 28, 2011, 05:16:09 pm
Hi All,

I am trying to compile a DirectX program by using the project wizard in Code::Blocks. I have set up all the paths to the libraries and the global variables as found in a short tutorial, but I am getting the following error when I try to compile:

k:\mingw\bin\..\lib\gcc\mingw32\4.5.2\..\..\..\libmingw32.a(main.o):main.c   undefined reference to `WinMain@16'

I've set the -mwindows option in Project->Build Options->Linker Settings, which I found by Googling, but I still get the error.
Any suggestions?
Title: Re: Using Code::Blocks to make DirectX program
Post by: MortenMacFly on October 28, 2011, 05:26:14 pm
Well, did you check the obvious, whether you do have a main function and you compile link it?

Without code it'll be very hard to help. Try to strip down the project to a minimal sample which you can attach here.
Title: Re: Using Code::Blocks to make DirectX program
Post by: Glooper on October 28, 2011, 07:12:40 pm
As I said in my post, I used the Code::Blocks Project Wizard to create the project, so yes it does have a WinMain and it is a minimal application. It compiles fine, the error is from the linker.
Title: Re: Using Code::Blocks to make DirectX program
Post by: stahta01 on October 28, 2011, 10:09:21 pm
Turn on full compiler logging

http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F (http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F)

And since the code is short, please post it in code tags!

Tim S.
Title: Re: Using Code::Blocks to make DirectX program
Post by: Glooper on October 28, 2011, 11:43:42 pm
It's OK, I've sorted it now.

It seems to be a problem with the DirectX9 wizard. The wizard generated code assumes a UNICODE build, but the project build options are set to _MBCS. I changed all references to unicode text in the main.cpp file then got the original undefined reference error. I then noticed an error in the WinMain line:

Code

Original line:
INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT )     <== used when building Unicode

New line:
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )     <== used for MBCS


Now it builds/links and runs fine.