Problem with VC++ 6.0

Hi everyone! I have some problems with compiling programs in vc++ 6.0 which has more than one file. For example - compiler stops when see class definition in header file? Why is that so? There are alway tons of bugs. Linking doesne’t work. I’ve tried to compile tutorials (which should be written correctly) bad it also fail. What can I do? Anyone knows?

You can start by telling us what happens, and what you do. You didn’t gave much information to go on. What error messages do you get?

Hi !

As bob said it’s difficult to help you with more information, post some of the error messages you get, that would be a good start.

Some common problems are:

  • You include gl.h without including windows.h first

  • You forget to add opengl32.lib to you project (unresolved externals)

  • Your code use glut but you have not installed glut (glut.h and glut.lib missing)

Just a few, but please do post a dump of some of the error messages, then it is much easier to help out.


I’ll post source. Just give me a bit of time. I’ll write something and i’ll post it. Meaby this is just lack of my c++ knowledge. Will see.


Ok. Here it is :

// ************ This is the main file ************* //

#include “main.h”

/* blah blah blah goes here */

// This is body of main.h

#ifndef MAINH
#define MAINH

#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>

#pragma comment(lib, “Winmm.lib”)
#pragma comment(lib, “OpenGL32.lib”)
#pragma comment(lib, “Glu32.lib”)
#include “vector.h”
#include “vector.cpp”


// vector.h
// decleration of vector

class VECTOR3D // it is just an example
float x,y,z;

void Set(float nx, float ny, float nz);

} wektor1;

// This body of vector.cpp

#include “vector.h”

void VECTOR3D::Set(float nx,float ny,float nz)
// **** VECTOR3D : is not a class or namespace name **** //
x = nx; // undeclared identifier etc…
y = ny;
z = nz;

That’s all. It seems that vector.cpp doesn’t see vector.h. But they should be linked together in main.h. What is wrong?

Thanks in advance.

The problem is that you include a source file as it it was a header file. In main.h, you include vector.h and vector.cpp, and in vector.cpp you include vector.h. This results in that vector.h is included twice in main.h, once directly and once indirectly from vector.cpp. Since you don’t have any include guards in vector.h (I assume that’s the entire file), you will have multiple declarations of the same name (VECTOR3D).

All header files should have include guards (that’s the #ifndef/#define/#endif in main.h in case you didn’t know) to prevent the file from being included several times, and you shopuld not include a source file. Source files should be added as separate file to your project.

Well, i know how include guards work. I’ve just forgot to cut "#include “vector.h” from vector.cpp. The error is not redefinition but “VECTOR3D : is not a class or namespace name”.

You said : “and you should not include a source file. Source files should be added as separate file to your project.”. ? I don’t get it. I added then from project->add to project-> New file… . Is there anything wrong with this way?

I would be great if you show me my mistake.


From main.h

#include “vector.cpp”

There you include a source file. Although it is legal to do so, it bad and will fail at some point to include code in a header file. You should add source file just like you said, by Project->Add to project, but if you have already done that, and also include the file via a header file, you will have problems.

You also said you forgot to cut #include “vector.h” from vector.cpp. Does that mean you no longer include vector.h in vector.cpp? That is a problem, since VECTOR3D is defined there, and the compiler does not know about it when compiling vector.cpp, assuming you have added vector.cpp to your project.

[This message has been edited by Bob (edited 02-08-2003).]

OK. Thanks. I’ll try it.