Author Topic: Using Code::Blocks to make DirectX program  (Read 6605 times)

Offline Glooper

  • Multiple posting newcomer
  • *
  • Posts: 11
Using Code::Blocks to make DirectX program
« 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?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Using Code::Blocks to make DirectX program
« Reply #1 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.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline Glooper

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Using Code::Blocks to make DirectX program
« Reply #2 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.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
Re: Using Code::Blocks to make DirectX program
« Reply #3 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

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

Tim S.
« Last Edit: October 28, 2011, 10:11:04 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Glooper

  • Multiple posting newcomer
  • *
  • Posts: 11
Re: Using Code::Blocks to make DirectX program
« Reply #4 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.