View Full Version : Linker Error

02-04-2002, 02:53 AM
This isn't a direct OpenGL question but if anyone can give me some assistance that would be great. I am having "Unresolved externel....." errors when attempting to program an OpenGL program. I am using different header files for each module of the program. There is a particular module that contains all my global variables and functions. When I declare the variable straight out, my compiler BCB5, says that there are multiple definitions of the variable. When I declare the variable with extern, I get the unresolved error.
Is there any hints anyone can give me?

02-04-2002, 07:42 AM
So what is the error?

We can't read your mind.

02-04-2002, 07:51 AM
Have you entered code to ensure a file gets included only once. This way you won't get it redefined because of multiple inclusions.




02-04-2002, 04:51 PM
Yep, you do need to make certain that your header files are "wrapped" to guard against multiple inclusion by the preprocessor:


But, if you wrap the header, you can still have trouble if your header file contains definitions. It is good practice for your header files to contain only declarations.

#ifndef _MYHEADER_H
#define _MYHEADER_H

extern int myinteger; // Ok, declaration of
// myinteger, it must
// be defined elsewhere

float myfloat; // risky, during
// compilation, if more
// than one .c/.cpp
// includes this header
// the symbol myfloat
// will be duplicated
// and many linkers
// will complain


I'm a little rusty on my C/C++, but I believe these facts to be correct.

[This message has been edited by ComoNo (edited 02-04-2002).]

02-04-2002, 05:35 PM
Why dont you try including #pragma once in the beginning of your code....

#pragma once

...... your code .........

02-05-2002, 06:04 AM
Sorry, I've never used pragma so I don't know how it works. ComoNo is right though. If you place only declarations in your header files it can save you a lot of headaches.

PS: Does anyone know where I can find a good MS VC++6.0 discussion forum? There's still a lot I need to learn about the program.