Wednesday, August 12, 2009

Mingw + DirectX

I am currently a student at University of Illinois, Chicago doing masters in Computer Science with focus on graphics programming. I decided to learn directx and what could be a better way to do that other than programming it?. I have microsoft Visual c++ installed on my system. But I am a big fan of g++. Hence I decided to do a small project with directx graphics and mingw compiler.

Trouble starts here. There is very little information on the internet about combining directX and mingw. Most of the users seem to use DevCPP or visual c++. Anyways without losing hope, I searched and found this useful website by link. Having this page as foundation I started the installation process. I thought to myself "what if there is little or no information about this topic on the net? I will experiment and write a blog about it" and here it goes.

I already have mingw's latest version. To learn more about Mingw with Opengl please visit my "Mingw + glsl" blog. I also have mingw utilities to use the reimp tool. Now reimp tool is used to convert *.lib files to Mingw compatible *.a files.

Next I downloaded directx sdk for windows Vista ( And yeah I have Vista) . Installed directx to C:\Program Files\Microsoft DirectX SDK (March 2009). Now to make directx libraries compatible with Mingw, I used reimp tool to convert all the *.lib files of C:\Program Files\Microsoft DirectX SDK (March 2009)\Lib\x64 to *.a files. I moved those reimp'ed files from to C:\MinGW\lib\directx. Created a new folder directx under lib for directx libraries.

Then I moved header files (*.h) files from C:\Program Files\Microsoft DirectX SDK (March 2009)\Include to C:\MinGW\include\directx. Directx folder will not be there under include, so created one.

Now in the program, include the header file as #include and while running compile command include the library as -ld3d9 for e.g:
g++ demo.cpp -ld3d9

I ran my first directX "hello world" sorta program from http://www.directxtutorial.com/ and it compiled and ran successfully. looking forward to learn more about DirectX

hope this piece of information helps you with g++ and DirecX combination.


4 comments:

Unknown said...

Hi, I'm trying to make DirectX SDK (August 2009) work with MinGW and I have several serious problems. The most important, I guess, is when I try to include DirectSound or XAudio header files, they require "sal.h", which is part of MSVC. (And also, there are many other warnings and errors, but I hope, that this header miht help with getting rid of them). But when I copied the sal.h from MSVC to MinGW I got internal compiler error. Any idea how to solve this problem?
(BTW I got the same issues with DX SDK March 2009)

Sujatha said...

hey jiri, can you copy paste the exact compiler error that you got?

blaklite said...

Hi ,

Usefull page as its about the only clear explanation I could find.
However when I tried I have at least 4 of the .lib files that wont convert to libxxx.a or xxx.def files (eg DxErr.lib, havnt figured out what the others were, only that they generated files like "0" and "437").

This is using the earlier versions of MinGWUtils (0..3, if I use 0.4.1 then it wont accept any of the .lib files, saying they are corrupted)

If I use the -s option to list the functions the DxErr.lib has a whole section of rubbish that can't be recognised by reimp.

!. Did you get these same problems, if not how not?

2. Isn't it a pain that M$ wont play by the rules?

Sujatha said...

Hey Blaklite,
thanks.
ya those files did not generate an exact DxErr.a for me too. Seems DxErr is not probable with MinGW. But if you dont use DxErr functions,and certainly not -lDxErr, then the non .a DxErr files should not be a problem for you. I am not using the error handling procedures of DirectX as of now, so this did not turn out so bad for me.

you can try this procedure. reimp DxErr9.lib creates an obj file. after reimp line type the following "ar rcs libdxerr9.a dxerr9.obj" this creates an archive from obj file to .a file. I read it somewhere in a forum. I am trying to test this using a program that requires DxErr library. If you
attempt this procedure, please do let me know how it turned out.

Or if you have DxErr.dll in your machine, then try the proceedure mentioned in this guide to convert the dll to .a file. I searched in my Vista machine but couldnt find DxErr.dll file, even if i did, i cannot distribute it to you because of the MS License restriction.

Well basically we are taking something written by MS for Visual Studio, to G++ for our convenience. so there arent any rules here to be followed by MS, if i am not wrong. That said, it would be great if MS would create cross compiler compatible modules for G++ fans like us.