Archived

This topic is now archived and is closed to further replies.

executor_2k2

Weird compile errors

Recommended Posts

executor_2k2    122
I getting the following compile errors: --------------------Configuration: GameDevelopment - Win32 Debug-------------------- Compiling... bubbles.cpp g:\program files\microsoft visual studio\myprojects\gamedevelopment\bubbles.cpp(68) : warning C4244: ''initializing'' : conversion from ''float'' to ''int'', possible loss of data main.cpp ParticleSystem.cpp TGALoader.cpp Linking... main.obj : error LNK2005: "unsigned char * cTGAcompare" (?cTGAcompare@@3PAEA) already defined in bubbles.obj main.obj : error LNK2005: "unsigned char * uTGAcompare" (?uTGAcompare@@3PAEA) already defined in bubbles.obj main.obj : error LNK2005: "struct TGA tga" (?tga@@3UTGA@@A) already defined in bubbles.obj main.obj : error LNK2005: "struct TGAHeader tgaheader" (?tgaheader@@3UTGAHeader@@A) already defined in bubbles.obj TGALoader.obj : error LNK2005: "unsigned char * cTGAcompare" (?cTGAcompare@@3PAEA) already defined in bubbles.obj TGALoader.obj : error LNK2005: "unsigned char * uTGAcompare" (?uTGAcompare@@3PAEA) already defined in bubbles.obj TGALoader.obj : error LNK2005: "struct TGA tga" (?tga@@3UTGA@@A) already defined in bubbles.obj TGALoader.obj : error LNK2005: "struct TGAHeader tgaheader" (?tgaheader@@3UTGAHeader@@A) already defined in bubbles.obj bubbles.obj : error LNK2001: unresolved external symbol _gluBuild2DMipmaps@28 main.obj : error LNK2001: unresolved external symbol _gluPerspective@32 Debug/GameDevelopment.exe : fatal error LNK1120: 2 unresolved externals Error executing link.exe. Creating browse info file... GameDevelopment.exe - 11 error(s), 1 warning(s) I have now idea what to do? Anyone have an idea? Thanks

Share this post


Link to post
Share on other sites
merlin9x9    174
Well, firstly, fix that float -to-int issue—do an explicit cast. Now, you'll need to link your project with glu32.lib because that's where the implementation of the GL Utility Library functions (such as gluPerspective are). Since you don't have anything linker errors involving OpenGL functions, I assume you already know how to specify the libraries you want linked. For future reference, though, look in MSDN and it will tell you which header and library to use for whatever function you're using. Finally, you need to use "include guards" in all of your header files. Those other linker errors are probably caused by one header being able to include another which had already been included. So, here's how you fix it for a file called myheader.h :

    
#ifndef _MYHEADER__H_
#define _MYHEADER__H_

// everything your header would normally have inside

#endif // _MYHEADER__H_



Of course, the particular name you use for the "include guard" constant is irrelevant, just as long as its unique throughout your project, which is why most people make it take a form vaguely resembling the particular header's name.

Edited by - merlin9x9 on January 28, 2002 11:35:47 PM

Share this post


Link to post
Share on other sites
terminate    259

to fix the first 8 linker errrors

on top of tga.h

#ifndef __TGA_H__
#define __TGA_H__

and at the bottom of tga.h

#endif

to fix the last 2

Add this to the top of your main file

#pragma comment(lib, "glu32.lib")

Share this post


Link to post
Share on other sites
executor_2k2    122
I've tried using include guards but they dont work. They are different for all headers, but if I insert #include "Tga.h" into my main.cpp i get even more of the above errors.
I have #include Tga.h in two different files. One is in TGALoader.cpp. And the other is in bubbles.cpp. bubbles.cpp calls LoadTGA() which loads a targa file. I think the include is necessary in both places.

Arent include guards supposed to keep the header from being included a second time? Or are they just for pretty looks?
Thanks in advance.

Edited by - executor_2k2 on January 28, 2002 12:25:45 AM

Share this post


Link to post
Share on other sites
merlin9x9    174
No, they actually are supposed to do stuff; they keep your header from being included more than once in each translation unit (vaguely, each source file). Are you positive that you''re making the include guards wrap everything in your headers? The only other thing I can think of is that you''re implementing your functions in your headers, which you should never do, unless they''re template functions or are declared as inline (using inline or __inline, in C++ and C, respectively). Otherwise, it must be done this way:

In myfile.h:
  
#ifndef _MYFILE__H_
#define _MYFILE__H_

extern unsigned char* cTGAcompare(int whatever);
...

#endif


In myfile.c:
  
unsigned char* cTGAcompare(int whatever)
{
...
}


The extern bit tells the compiler that the actual object (a function, in this case) is somewhere else. And then you do the implementation in a source file (.c or .cpp, depending on whether you''re using C or C++, respectively).

Share this post


Link to post
Share on other sites