Need help compiling example code (MinGW and DirectX9)

This is a discussion on Need help compiling example code (MinGW and DirectX9) within the Game Programming forums, part of the General Programming Boards category; I have the following tools at my disposal: A fresh windows install The Windows SDK installer The MinGW installer The ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    19

    Need help compiling example code (MinGW and DirectX9)

    I have the following tools at my disposal:
    A fresh windows install
    The Windows SDK installer
    The MinGW installer
    The DirecX9 SDK installer

    I'm trying to compile the simple program below. Its from a CD which is from a book.

    How do I compile the program? Be as idiot proof as possible.
    Attached Files Attached Files
    Last edited by scwizard; 07-24-2008 at 10:19 AM.

  2. #2
    Registered User
    Join Date
    Dec 2006
    Posts
    19
    The images associated with the program.

    Background converted from bmp to png due to attachment size limit. Convert back so the program doesn't complain when you run it.

    Although these images aren't really necessary since the program will compile fine without them obviously, and successfully compiling is the only goal here.
    Attached Images Attached Images   

  3. #3
    ---
    Join Date
    May 2004
    Posts
    1,379
    How do I compile the program? Be as idiot proof as possible.
    Press the compile button?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by sand_man View Post
    Press the compile button?
    That assumes that OP has an IDE which provides a project compile button.

    If he/she is using gcc-mingw on it's without an IDE, the command line would be something like this:
    Code:
    gcc -c -Wall [all .cpp files]
    gcc -o something [all the names of .cpp files but with .o instead of .cpp] -ld3d9a
    That's a rough guestimate, as I can't actually see the names of the .cpp files when posting this.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Dec 2006
    Posts
    19
    Quote Originally Posted by matsp View Post
    That assumes that OP has an IDE which provides a project compile button.

    If he/she is using gcc-mingw on it's without an IDE, the command line would be something like this:
    Code:
    gcc -c -Wall [all .cpp files]
    gcc -o something [all the names of .cpp files but with .o instead of .cpp] -ld3d9a
    Thanks for the effort, but the reason I'm asking this question is because I'm running into unexpected difficulties.

    Could you be a bit more specific? Obviously for example if I just install MinGW and none of the other stuff I run into "can not find d3dx9.h"

    That's a rough guestimate, as I can't actually see the names of the .cpp files when posting this.
    Yes you can, they're attached to the OP names and all :P
    Last edited by scwizard; 07-24-2008 at 10:16 AM.

  6. #6
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    If you click on Advanced Reply, I think attachments don't show up. *checks* Yep, the names are gone.

    Could you be a bit more specific? Obviously for example if I just install MinGW and none of the other stuff I run into "can not find d3dx9.h"
    You'll need to install the DirectX SDK. "d3dx9.h" is "Direct 3D (DirectX 9)", so that's what you need.

    Make sure you've installed a compiler before you install DirectX, though.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  7. #7
    Registered User
    Join Date
    Dec 2006
    Posts
    19
    By this do you mean that I should install the DirectX SDK into the MinGW folder?

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Uh . . . I'm not sure; I've never used DirectX. Strangely enough, I recognize those images from when I was flipping through that book, though . . . .

    But I think this guy has. http://www.spacejack.org/games/mingw/mingw-dx.html

    (Note the reference to the SDL! )
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Registered User
    Join Date
    Dec 2006
    Posts
    19
    Quote Originally Posted by dwks View Post
    Uh . . . I'm not sure; I've never used DirectX. Strangely enough, I recognize those images from when I was flipping through that book, though . . . .

    But I think this guy has. http://www.spacejack.org/games/mingw/mingw-dx.html

    (Note the reference to the SDL! )
    I followed the instructions on that site for "the easy way"

    Code:
    In file included from C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/d3dx9mesh.h:15,
                     from C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/d3dx9.h:46,
                     from winmain.cpp:6:
    C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/dxfile.h:240: error: stray '\26' in program
    In file included from C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/d3dx9mesh.h:15,
                     from C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/d3dx9.h:46,
                     from winmain.cpp:6:
    C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/dxfile.h:240:2: warning: no newline at end of file
    In file included from C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/d3dx9mesh.h:15,
                     from C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/d3dx9.h:46,
                     from game.h:10,
                     from game.cpp:6:
    C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/dxfile.h:240: error: stray '\26' in program
    In file included from C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/d3dx9mesh.h:15,
                     from C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/d3dx9.h:46,
                     from game.h:10,
                     from game.cpp:6:
    C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/dxfile.h:240:2: warning: no newline at end of file
    game.cpp: In function `int Game_Init(HWND__*)':
    game.cpp:35: warning: passing NULL used for non-pointer converting 2 of `IDirect3DSurface9* LoadSurface(char*, D3DCOLOR)'
    game.cpp: In function `void Game_Run(HWND__*)':
    game.cpp:97: error: `D3DXSPRITE_ALPHABLEND' was not declared in this scope
    game.cpp:116: error: no matching function for call to `ID3DXSprite::Draw(IDirect3DTexture9*&, RECT*, NULL, D3DXVECTOR3*, D3DCOLOR)'
    C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/d3dx9core.h:228: note: candidates are: virtual HRESULT ID3DXSprite::Draw(IDirect3DTexture9*, const RECT*, const D3DXVECTOR2*, const D3DXVECTOR2*, FLOAT, const D3DXVECTOR2*, D3DCOLOR)
    In file included from C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/d3dx9mesh.h:15,
                     from C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/d3dx9.h:46,
                     from dxgraphics.cpp:6:
    C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/dxfile.h:240: error: stray '\26' in program
    In file included from C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/d3dx9mesh.h:15,
                     from C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/d3dx9.h:46,
                     from dxgraphics.cpp:6:
    C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/dxfile.h:240:2: warning: no newline at end of file

  10. #10
    Registered User
    Join Date
    Dec 2006
    Posts
    19
    Hmm that's odd, apparently instead of a line break at the end of the file one of the files had a funny character.

    I have no idea how that happened, weird. Well stuff calmed down a bit after I deleted that character:

    Code:
    game.cpp: In function `int Game_Init(HWND__*)':
    game.cpp:35: warning: passing NULL used for non-pointer converting 2 of `IDirect3DSurface9* LoadSurface(char*, D3DCOLOR)'
    game.cpp: In function `void Game_Run(HWND__*)':
    game.cpp:97: error: `D3DXSPRITE_ALPHABLEND' was not declared in this scope
    game.cpp:116: error: no matching function for call to `ID3DXSprite::Draw(IDirect3DTexture9*&, RECT*, NULL, D3DXVECTOR3*, D3DCOLOR)'
    C:/Documents and Settings/Administrator/Desktop/****/dx9sdk/Include/d3dx9core.h:228: note: candidates are: virtual HRESULT ID3DXSprite::Draw(IDirect3DTexture9*, const RECT*, const D3DXVECTOR2*, const D3DXVECTOR2*, FLOAT, const D3DXVECTOR2*, D3DCOLOR)

  11. #11
    Registered User
    Join Date
    Dec 2006
    Posts
    19
    Oh this is all caused by an old version of the directx SDK.

    I regret not noticing this sooner.

    EDIT: Now I have this:

    Code:
    game.cpp: In function `int Game_Init(HWND__*)':
    game.cpp:35: warning: passing NULL used for non-pointer converting 2 of `IDirect3DSurface9* LoadSurface(char*, D3DCOLOR)'
    C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp/ccpvfu0l.o:winmain.cpp:(.text+0xfc): undefined reference to `GetStockObject@4'
    collect2: ld returned 1 exit status
    To compile it I'm running:
    Code:
    g++ winmain.cpp game.cpp dxgraphics.cpp -o test.exe -I"C:\Documents and Settings\Administrator\Desktop\****\dx9sdk\Include" "C:\Documents and Settings\Administrator\Desktop\****\dx9sdk\Lib\x86\d3dx9.lib" "C:\Documents and Settings\Administrator\Desktop\****\dx9sdk\Lib\x86\d3d9.lib" -fcheck-new
    Another edit: Nevermind, I still don't have the latest edition apparently....

    Final edit: the remaining problem is that I had to link GDI, but the book didn't say so.

    It finally works.
    Last edited by scwizard; 07-25-2008 at 12:15 PM.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21