# Dev-C++ build error in Makefile



## Meriadoc (Jul 12, 2004)

Hi, this is my first time at this forum, so if my question is misplaced, I'm sorry.

Anyway, I'm trying to get a basic Direct3D 8 window running in Dev-C++, and I get a build error ([Build Error] [BasicDirect3DApp.exe] Error 1) in the makefile.

I think that I linking linking the library file incorrectly. In the Project Options box under Directories, I add the "C:\DXSDK\lib" directory, in which the file "d3d8.lib" (the one I need) is contained. Under the Parameters tab, in the Linker box, I put "d3d8.lib". I have also tried using the "Add Library or Object" button, and I get a different error with that, one that seems like the Direct3D file has a problem with it.

My source code is fairly long to post here, but if you need that to help I can post it, along with my compiler log. I just have to type it out manually, since it won't let me just copy the text. 

Thank you for any help.


----------



## Shadow2531 (Apr 30, 2001)

Provide a link to your source files including just the lib file needed. (don't want to dl the DxSDK right now).

We can attempt to compile it at the command line with Mingw (what devc++ uses). Assuming your code is correct, DevC++ is most likely not invoking the proper command.

If you don't want to show your code, make a test case program that we can work with to determine what's wrong.


----------



## Meriadoc (Jul 12, 2004)

Ugh. I can't get the files uploaded correctly. That's what I get for using a free host.  I'll keep trying. Thanks for (trying to) help.


----------



## Shadow2531 (Apr 30, 2001)

The reason it won't compile is because there is an error.

"undefined reference to Direct3DCreate8"

There may be more errors. Have to take care of the Direct3DCreate8 error first to find out.

Here's how I have things setup.

Devc++ uses mingw if you didn't know.

First off, I have mingw installed to c:\mingw and have c:\mingw\bin set in the path.

In c:\mingw\include, I created a folder named dxsdk.

I copied all contents of c:\dx90sdk\include to c:\mingw\include\dxsdk

So when I include d3d8.h in basicdirect3dapp.cpp, I do it like this:

#include <dxsdk/d3d8.h>

Then I copied C:\DX90SDK\Lib\d3d8.lib to c:\mingw\lib and renamed the file to libd3d8.a so I can use -ld3d8 to include the library.

Then at the command line in the same directory as basicdirect3dapp.cpp , I used the following command

g++ -Wall -W basicdirect3dapp.cpp -o basicdirect3dapp -ld3d8 -mwindows

It won't compile yet till all errors are taken care of.

So you should add c:\dev-cpp\bin to the path.
Create c:\dev-cpp\include\dxsdk and copy the DirectX inlude files to it.
Copy d3d8.lib to c:\dev-cpp\lib and rename it to libd3d8.a.

Then compile on the command line and not use the devc++ IDE.
That should eliminate devc++ as a problem, but I still think the error is your problem.

Then you can post your basicdirect3dapp.cpp (using the code tags) so everyone can see it and try to figure out what's wrong.

Of course I'm thinking you can't use MS's sdk libs with mingw and you have to get mingw compatible libs.

(To others, I obviously have the source of the program.)


----------



## Shadow2531 (Apr 30, 2001)

Got it to comple.

Scratch the MS SDK includes and libraries. Can't use them in their current state. (not saying that you can't with more work)

Download the mingw compatible SDK

http://www.bloodshed.net/dev/packages/index.html

I put the include files from that download in c:\mingw\include\dxsdk and the lib files in c:\mingw\lib\dx-lib

Used this command

g++ -Wall -W basicdx.cpp -o basicdx -L c:\mingw\lib\dx-lib -ld3d8 -mwindows

Your command would be more like


```
g++ -Wall -W BasicDirect3DApp.cpp -o BasicDirect3DApp -L c:\dev-cpp\lib\dx-lib -ld3d8 -mwindows
```
Knowing all that, you should be able to compile now.


----------



## Meriadoc (Jul 12, 2004)

I was (in the past) able to compile this project using the Dev-C++ DirectX8 pack, but the actual files have different names or something. So when I tried to move on, I couldn't progress because the book I'm using assumes that I have the MS SDK. I'll go ahead and compile anyway, and then I might be able to figure out how to progress from there.

EDIT: I compiled and ran the program and everything works great (I didn't have to use a command-line compiler, since I'm not sure how to access Dev-C++'s and haven't successfully used one before). The only thing was that I had to use the "Add Library or Object" button to link the library. I think I'm missing something (I did add the correct directory to the "directories" library tab).

Now, I have to get another project compiled. If I can figure this one out, I'll likely be in good shape to go on my own from there. It requires me to link d3d8.lib, d3dx8.lib, and dxerr8.lib. The problem is, the Dev-C++ library doesn't include the file libdxerr8.a. I don't know what I should link (besides libd3d8.a and libd3dx8.a).


----------



## Shadow2531 (Apr 30, 2001)

Remember that DevC++ is not a compiler and it uses the commandline mingw compiler(gcc).

All devc++ does is send the command to the compiler.

Anyway, there may be a more complete mingw dx sdk. There also may be a way to convert the ms sdk.

Also, you can download the micrsoft visual c++ toolkit for free. It should work with the MS SDK. However, the toolkit doesn't come with all the standard include files so you will have to obtain them from somewhere.

Using mingw's includes works with the toolkit for a lot of things, but they didn't help me compile the dx program with the toolkit.

I'll look into converting the whole dx9SDK and let you know what I find.


----------



## Meriadoc (Jul 12, 2004)

Thank you. Is there a way for me to access the command line compiler without the Dev-C++ IDE?


----------



## Shadow2531 (Apr 30, 2001)

Yes.

look for g++.exe

I'm thinking it's in c:\dev-cpp\bin

Read above posts to see how to compile things.

I don't use devc++, but I have it installed for the dx testing we're doing.

However I downloaded devc++ without the compiler.

http://sourceforge.net/project/showfiles.php?group_id=10639&package_id=12148&release_id=148734

The second download on that page is the editor only.

The MinGW compiler that comes with devc++ is an older version than I use.

What I would do is uninstall your existing devc++ and delete the c:\dev-cpp directory.

Goto http://www.nuwen.net/ , click on the c++ link and download the MinGW distro. Install it to c:\MinGW so that g++.exe is in c:\MinGW\bin. Read all the info on the c++ page too.

Install the editor-only version of devc++ to c:\dev-cpp and set devc++ to use MinGW via options.

However, you don't need devc++ at all.


----------



## Shadow2531 (Apr 30, 2001)

I'm checking out this to see if it will work

http://lair.gamedeveloper.net/search/entityview.php?eid=641


----------



## Shadow2531 (Apr 30, 2001)

O.K. Here's the deal. the MS .h files works with MinGW. It's just the lib files.

To fix the lib files so they work with MinGW, you need to use reimp.

download the MinGW utilities. Among the other utilities is reimp.exe

http://prdownloads.sf.net/mingw/mingw-utils-0.3.tar.gz?download

At the command line, just type

reimp file.lib to convert it to a compatible libfile.a and output file.def

Once you have all the MS SDK files converted to lib<file>.a files, put all those .a files in c:\mingw\lib . Then you can include them like this.

g++ -Wall -W file.cpp -o file -ld3d8 -mwindows

where "d3d8" is the name of the library.

If you would like to keep the MS SDK libs separate, put them in c:\MinGW\lib\msdx-lib and include them like this.

g++ -Wall -W file.cpp -o file -L c:\mingw\lib\msdx-lib -ld3d8 -mwindows

For the MS SDK .h files, put them in c:\mingw\include\msdx

When you include one of those use in your program:

#include <msdx/d3d8.h>


----------



## Meriadoc (Jul 12, 2004)

Thanks. I'll check and make sure that I can get it working. One more question. Would it be a good idea (and would it be possible) to use the compiler that comes with the MS VC++ toolkit with the Dev-C++ interface? (Or without it, just use the command line?) What would you recommend?


----------



## Shadow2531 (Apr 30, 2001)

Here's the DX9 mingw-compatible SDK with ALL the standard libs

2.1MB is a lot better than the 182MB ms SDK download.


----------



## Meriadoc (Jul 12, 2004)

It doesn't have "libdxerr8.a" for one. And I don't understand how to use reimp...


----------



## Shadow2531 (Apr 30, 2001)

That one doesn't need to be converted.

Just rename dxerr8.lib from the ms sdk to libdxerr8.a and it should work. Put it in the lib folder where you have the other mingw-compatible libs.

You can just rename all the ones that are missing from filename.lib to libfilename.a. reimp only converts and renames libs that need it. If the lib doesn't need it, reimp doesn't even rename the file to libfilename.a. 

I forgot to include the ones that didn't need converted. I'll fix that when I get a chance. It will increase the download to 8.43MB. You can save yourself the time by just renaming the few files.


----------



## Meriadoc (Jul 12, 2004)

One more question: Where do I put "sourcecode.cpp"? I tried in the C:\MinGW\bin and in the C:\MinGW directories and it couldn't find it.


----------



## Shadow2531 (Apr 30, 2001)

You put it wherever you want. You just have to add c:\mingw\bin to your path.

For Win2K/XP, you

right-click on MyComputer
Left-click on properties
Switch to Advanced tab
click "Enviroment variables" button

Under "system variables" is Path

Edit it and add *;c:\mingw\bin* to it

also create a new system variable named *RM* and give it a value of *del*

If you need to do this for win95/98/ME

http://forums.techguy.org/showpost.php?p=1784133&postcount=9


----------



## Shadow2531 (Apr 30, 2001)

For a text editor:

EditPlus
UltraEdit
Xemacs
Metapad
Arachnophilia
gvim

You can use google to find them. You'll probably like metapad.

Whatever editor you use, for .cpp files, set the indent-length to 4 and set it to insert spaces instead of tabs. Tabs are nasty.


----------



## Meriadoc (Jul 12, 2004)

I already did that path thing. And what exactly do you mean by "wherever I want"? I doubt it searches my entire hard drive for the file...


----------



## Shadow2531 (Apr 30, 2001)

Well if you had command prompt open and then set the path without closing the the command prompt and reopening it, then it won't honor the new path setting.

Anyway, you can do it like this.

put source.cpp on your desktop.

open a command prompt and goto your desktop directory. That will be c:\windows\Desktop or c:\documents and settings\<user profile>\desktop

Then type your g++ command.

e.g.

C:\Documents and Settings\<user profile>\Desktop>g++ -Wall -W hello.cpp -o hello

Note: just because you put source.cpp in a directory that's in the path, doesn't mean g++ can find it no matter where you type the command. So don't rely on that.


----------



## Shadow2531 (Apr 30, 2001)

If it makes it easier for you.

create the directory c:\dev and save all your files to there

Right-click on the desktop
New>shortcut
type cmd.exe
Name it *Development*
Click finish
right click on the Development shorcut
On the shortcut tab, modify "start in" to *c:\dev*

Then whenever you want to complie something, just click on the development shortcut.

e.g.

create a hello world pogram
create a hello folder in c:\dev
save hello.cpp to c:\dev\hello
click the development shortcut
type *cd hello* to change to the hello directory

Then type your command.

use command.com instead of cmd.exe if using win95/98/Me


----------



## Meriadoc (Jul 12, 2004)

Okay, everything is going well, except it finds errors in the .h files. Are you sure there is no need for a different version of headers? This is the error I get.


----------



## Meriadoc (Jul 12, 2004)

Okay, it compiles. I just deleted an extra space at the end of "dxfile.h". I got the updated MinGW files, so you can get rid of them if you want. Thank you very much for al your help.


----------



## Shadow2531 (Apr 30, 2001)

O.K.

If you notice any more .h files that have that at the end, let me know. dxfile.h should be the only one.

Glad you got it working.

Also just FYI, that mingw distro comes with upx. It will pack the exe to make it smaller. Also added -s will strip the dubugging code to make things smaller.

e.g.

```
g++ -Wall -W file.cpp -o file -ld3d3 -mwindows -s && upx -qqq --best file.exe
```
That will make the exe a lot smaller.

-mwindows tells the compiler to not create a dos window, so if you are compiling a commmand line program, you probably don't want it to not create a dos box.


----------

