# Dev C++ library linking--need help please



## compugeekpro (Jul 31, 2004)

Hi there...I'm new to this forum. I just got done with a chapter in a windows game programming book and the code in the chapter won't compile. I have gotten all code up to this point (chapter 6) to compile. It seems to me that the project I am working on isn't including the libmsimg32.a file. I clicked on "Add library or Object" and selected the libmsimg32.a file and clicked "OK".

Here's my error:

Bitmap.cpp In member function `void Bitmap:: Draw(HDC__*, int, int, int, long unsigned int)':

Line 226: Bitmap.cpp `TransparentBlt' undeclared (first use this function)

Makefile.win [Build Error] [Bitmap.o] Error 1

The code is right off the cd-rom and I know it works (I just got done compiling a slideshow program that uses bitmaps). Am I linking the library right? I have my library folder set as: "C:/DevCpp/lib/" already. It says in the book that the TransparentBlt function should be in the msimg32.lib library...which is equivelent to libmsimg32.a in Dev C++.


----------



## Shadow2531 (Apr 30, 2001)

Add your c:\dev-cpp\bin directory to the path if it isn't already. (Or the path where your g++.exe is)

Directions for that

Put your Bitmap.cpp on the desktop

Open the command prompt and change to your desktop directory

Type the following command and see if you get any errors

g++ -Wall -W Bitmap.cpp -o Bitmap -lmsimg -mwindows -s


----------



## compugeekpro (Jul 31, 2004)

Okay...it found the library, but I got a different error. 

Here's the error:
../lib/gcc-lib/mingw32/3.3.1/../../../libmingw32.a(main.o)(.text+0x97):main.c:undefined reference to '[email protected]'

If you have any ideas on what's causing this error...I'd appreciate your help. By the way...thanks for the reply to my last post.


----------



## Shadow2531 (Apr 30, 2001)

I don't know what you are compiling exactly so you might not need the -mwindows part in the command.

If that's not the problem, then it's probably that you didn't define main()

int main() {
code goes here
}

or you didn't

#include <windows.h>

Hard to say without knowing more about the code.

You might be able to put

int main() {

}

with nothing in it to get it to compile.


----------



## compugeekpro (Jul 31, 2004)

I'm sorry I forgot to give the full project details. Like I said, this was a project out of the book. I am at Chapter 6 and have been able to compile everything up until now (I had to include a library). My project consists of a few header files, a few c++ files, two pictures (BMP), and a resource file for the bitmap pictures. The program is supposed to be where you can control this UFO picture (the color magenta is transparent so the UFO is rounded and the backround shows through) with the arrow keys on your keyboard. It is built off of a game engine that you add on to throughout the book (GameEngine.cpp and GameEngine.h). For this particular program you add the transparency function out of the msimg32.lib library (which should be equivalent to Dev C++'s libmsimg32.a). In order to do basic Bitmap stuff, you have a Bitmap class in Bitmap.cpp and Bitmap.h. The main program (Win Main, since it is a windows program) is called UFO.cpp and UFO.h which use functions from GameEngine.cpp and Bitmap.cpp (with the libmsimg32.a included) to create the game. 

Here's what I did already:
1.) Went to project options and added the libmsimg32.a library by using the "add Object or Library" button. Error: same as my first post.
2.) Changed it manually to -lmsimg32 and tried to compile. I got the same error
3.) Tried what you just said to do (I substituted Bitmap.cpp for UFO.cpp and added all project files to my desktop) and got a different error (the one I just posted). 

That's about all the information I can give. This is really getting me annoyed because I want to use a nice visual free compiler (Dev C++) that I'm used to to make programs and small games. Please give me some more advice...I really want to get on to the rest of the book. Thanks.


----------



## Shadow2531 (Apr 30, 2001)

You might have to do something like

g++ -Wall -W UFO.cpp GameEngine.cpp Bitmap.cpp -o programname -lmsimg -mwindows

plus add -l<library> for any other libs you need to link.

to include libname.a, you do -lname etc.

.Or you might have to compile (but not link) bitmap.cpp and gameEngine.cpp to object files and then add them when you compile ufo.cpp.


----------



## compugeekpro (Jul 31, 2004)

Hmmm...I'm getting some different, more defined errors when I try the first thing you stated. I will mess around with that for a bit and let you know if i get it working. By the way, what are some of the commands you are using...what do they do? For instance, what does -Wall -W do? I know -o stands for output or whatever you name it.


----------



## compugeekpro (Jul 31, 2004)

Okay...I tried compiling all of them together...here's a few of the errors I got:

A few warnings about "unused parameters" which don't affect the overall build process (so I don't care about those)

Bitmap.cpp:226: error: 'TransparentBlt' undeclared (first use this function)
Bitmap.cpp:226: error: (Each undeclared identifier is reported only once for each function it appears in.)

That's the only error. It's back where I started, BUT it gives the second half of it. I never saw "(Each undeclared identifier is reported only once for each function it appears in.)" . Could you break that down for me...what does it mean?


----------



## Shadow2531 (Apr 30, 2001)

Are you doing this on win98?

Look in the wingdi.h header file

that transparentblt function is only defined if your os supports transparencies. e.g win2K and WinXP.


----------



## compugeekpro (Jul 31, 2004)

I Do have windows xp service pack 1.


----------



## compugeekpro (Jul 31, 2004)

I have just found a little information that narrows my error down more. I found out that it has to do with the wingdi.h and the windows.h header files in Dev-C++, but I don't know how to resolve the error.

I did look in the wingdi.h header file...here's what I found:

#if (WINVER>= 0x0500)
BOOL WINAPI AlphaBlend(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION);
BOOL WINAPI GradientFill(HDC,PTRIVERTEX,ULONG,PVOID,ULONG,ULONG);
BOOL WINAPI TransparentBlt(HDC,int,int,int,int,HDC,int,int,int,int,UINT);
#endif

I looked in windows.h for the include of wingdi.h...here's what I found:

#if !(defined NOGDI || defined _WINGDI_H)
#include <wingdi.h>
#endif


----------



## compugeekpro (Jul 31, 2004)

my compile log:

Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\SMG\My Documents\My Programming\C++ Programming\Sams-TYS-Game Programming\Chapter 6\UFO\Makefile.win"
Executing make...
make.exe -f "C:\Documents and Settings\SMG\My Documents\My Programming\C++ Programming\Sams-TYS-Game Programming\Chapter 6\UFO\Makefile.win" all
g++.exe -D__DEBUG__ -c Bitmap.cpp -o Bitmap.o -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include/c++/mingw32" -I"C:/Dev-Cpp/include/c++/backward" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include" -g3

Bitmap.cpp: In member function `void Bitmap:: Draw(HDC__*, int, int, int, long

unsigned int)':
Bitmap.cpp:226: error: `TransparentBlt' undeclared (first use this function)
Bitmap.cpp:226: error: (Each undeclared identifier is reported only once for 
each function it appears in.)

make.exe: *** [Bitmap.o] Error 1

Execution terminated


----------



## Shadow2531 (Apr 30, 2001)

-Wall -W just turns on the warnings so you don't get away with crappy code.

The "each error only reported once" error just means there may be more of the same type of errors or means that once your fix those, you may have other errors.

As for the errors, I cannot investigate more unless I have the source files so I can try to compile it. It's possible that some of the code that is not compatible with mingw without some fixes.


----------



## compugeekpro (Jul 31, 2004)

I decided to go ahead and put my project in a zip file. You can download it at: http://home.everestkc.net/compugeek/

Just click on the UFO.zip link.

I really appreciate all the help.


----------



## Shadow2531 (Apr 30, 2001)

If at first you don't succeed, cheat.

IN wingdi.h

change the >= to <= 

#if (WINVER<= 0x0500)
BOOL WINAPI AlphaBlend(HDC,int,int,int,int,HDC,int,int,int,int,BLENDFUNCTION);
BOOL WINAPI GradientFill(HDC,PTRIVERTEX,ULONG,PVOID,ULONG,ULONG);
BOOL WINAPI TransparentBlt(HDC,int,int,int,int,HDC,int,int,int,int,UINT);
#endif

I successfully compiled it without the icons. After modifying wingdi.h.

Cannot guarantee that will solve all your problems, but that should help.


----------



## compugeekpro (Jul 31, 2004)

:up: Well...it worked for me too. Thank you VERY much! Now I can go program some cool games.


----------



## Shadow2531 (Apr 30, 2001)

I ended up compiling it with the icons so I could see the background etc. Neat.

FYI, here's the commands to compile. Although it is ideal to make a MAKEFILE, I just saved the following 2 lines as build.bat. Then just double-click the bat file or type build at the command line.

windres -i UFO.rc -o ufoicon
g++ -Wall -W UFO.cpp Bitmap.cpp GameEngine.cpp ufoicon -o ufo -lmsimg32 -mwindows -s

The first line is how you create the icon object file so you can include it.


----------



## compugeekpro (Jul 31, 2004)

Thanks again...It is pretty cool isn't it?


----------



## Shadow2531 (Apr 30, 2001)

compugeekpro said:


> Thanks again...It is pretty cool isn't it?


no, it's cool.


----------

