Skip to main content
GameDev.net gamedev.net
🔒 Locked

Undefined Types VC++ 7.1

Started by Nox587 Dec 10, 2005 at 10:11 AM 7 replies 1.2k views
Original Post
Nox587
Nox587
I'm expanding this library I'm writing, and am running into a huge problem I can't get around. For some reason whenever I compile this I get about 147 errors all about undeclared identifiers, and undefined types. The strange thing about it is this. I have a class header file, and a class definition file that includes the header. Its telling me it can't find the class, and the members of the class, and any other class I include and use, it won't find either. I've checked for circular includes and I don't have any of that going on. I can even type in a class or the namespace with the scope resolution like IGameEvent:: and it will list the members, it just doesn't find them at compile time. I wish that I could be more specific, but I have a lot of code, far to much to post. If there is some common mistake I could be making that would cause VC++ to not be able to find these things at compile time maybe...
Conner McCloud
Conner McCloud
You mention this is for a library. Is it when you compile the library that this is a problem, or when you compile code that uses the library? If the latter, are the object files included in your linker settings? Under VC2005, check Project->Properties->Configureation Properties->Linker->Input->Additional Dependancies. Make sure you list your library files there. Alternatively, you can include some pragmas in your header files to achieve the same effect. #pragma comment("lib", "libraryname") is the proper syntax, I believe, but MSDN can give you more information.

CM
d_emmanuel
d_emmanuel
Sounds like NOX587 is getting compile time errors and not linker errors.

Are you attempting to use an existing library with another project? If so, then you'll need to add the include path to the library to the "Additional Include Directories" property.

You said you're using namespaces. Have you made sure that the existing library is visible in the namespace scope of the code you're adding?
iMalc
iMalc
Check that you haven't made the same silly mistake that I've made before: Splitting an existing header into two files by making a renamed copy and removing bits from each. The problem comes from not changing the little bit at the top...
#ifndef MYHEADERFILE_H#define MYHEADERFILE_H
As two files having the same bit like that at the top would cause what you are seeing. Can be a real pain to track down when your working under the assumption that a #include does include the file, but clearly it wont be in this case.
Well, I hope that helped.
Nox587
Nox587
Thanks for the replies, I am compiling the library itself at the moment. It uses the Ogre library, but I've got that library visible to my project. As for my namespace being visible, I'm slightly confused by your question. But the way I have this setup is that this library is all part of a namspace called theRock. In my header files I have

namespace theRock
{
code...
}

and in the cpp files I have

using namespace theRock;

So I assume that the namespace is visible. I checked all my definitions at the tops of my header files, they seem ok. One thing I noticed however when looking at source code for Ogre, is that it has a file OgreRoot.h, but there definitions are

#ifndef __ROOT__
#define __ROOT__

and the class is called root, not ogreRoot. I have a similar situation, with a file named theRock.h but the class is named rockCore, should I change the definition to

#ifndef __ROCKCORE__
#define __ROCKCORE__

or should I leave it using THEROCK_H, or would this make a difference there at all. Thanks for the help, its much appreciated
Nox587
Nox587
*bump*
Bezben
Bezben
The __ROCKCORE__ in

#ifndef __ROCKCORE__
#define __ROCKCORE__

is just to stop the compiling including the header multiple times, it doesn't matter what you use as long as it is unique and not used elsewhere. I tend to use the name of the file capitalised, with underscores either side, and an underscore instead of a dot -> #ifndef _FILE_HPP_

It might help if you post the actual text of the error messages...
load_bitmap_file
load_bitmap_file
Quote:
Original post by Nox587
In my header files I have

namespace theRock
{
code...
}

and in the cpp files I have

using namespace theRock;

So I assume that the namespace is visible. I checked all my definitions at the tops of my header files, they seem ok.


You're not doing something like:
//theRock.hnamespace theRock{	class A;}//theRock.cppusing namespace theRock;class A{	//...};


are you? That is, you define your namespace members like:
theRock::A{	//...};//ornamespace theRock{	class A	{		//...	};}


right? If you don't do either of the last two methods, then I don't think you can just say "using namespace whatever" and not explicitly qualify the namespace when defining the members.

Quote:
One thing I noticed however when looking at source code for Ogre, is that it has a file OgreRoot.h, but there definitions are

#ifndef __ROOT__
#define __ROOT__

and the class is called root, not ogreRoot. I have a similar situation, with a file named theRock.h but the class is named rockCore, should I change the definition to

#ifndef __ROCKCORE__
#define __ROCKCORE__

or should I leave it using THEROCK_H, or would this make a difference there at all. Thanks for the help, its much appreciated


The name of the header guard doesn't really matter, it just needs to be unique, so it's common sense (and convention) to use the name of the file and maybe a prefix that's the name of the project. However, __ROCKCORE__ isn't a good choice because identifiers starting with double underscores (or was it a single underscore? Or both?) are reserved for the compiler.
Nox587
Nox587
ok, well thanks for that bit of info, appreciate it. I finnaly figured out my problem. First of all, no I wasn't using either of those two methods what I do is have a .h file like this

namespace theRock
{
class A
{

};
}

and a .cpp file

using namespace theRock;
class A::A()
{

}


but my problem was, is a temporarily had a class predefinition in one of my files that I meant to take out. well I didn't take it out, and so I end up with 278 some odd errors from it....but its fixed, again thanks for all the help.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.