-
linking problem
I am getting the following errors when trying to compile my code:
DLLMain.obj : error LNK2001: unresolved external symbol "class BMLClient netClient" (?netClient@@3VBMLClient@@A)
Desktop\Walker26.dlc : fatal error LNK1120: 1 unresolved externals
the line that is causing it is :
Code:
int az = netClient.GetAzimuth();
netClient is declared as
Code:
extern BMLClient netClient;
in the same file
the original declaration is in another header file BMLDrawable.h:
Code:
class BMLDrawable: public osg::Drawable {
public:
BMLDrawable();
virtual ~BMLDrawable();
virtual osg::Object* cloneType() const
{
return new BMLDrawable();
}
virtual osg::Object* clone(const osg::CopyOp&) const
{
return new BMLDrawable();
}
bool computeBound() const;
virtual void drawImplementation(osg::State& state) const;
protected:
BMLClient netClient;
};
GetAzimuth is declared as
Code:
int GetAzimuth(void) { return m_nAzimuth; }
in the BMLClient class
is anyone familiar with what this error means?
-
If you declare it as extern in a header file, you must define it in a source file that is compiled and linked into your project. It is the same syntax without the extern (unless you want to add constructor arguments).
-
I don't have it declared in a header file, it's in my main cpp file...
-
If you have an extern variable in a file, then the compiler assumes that you've declared the variable in another file and leaves the linker to find out where. If the linker can't find where you declared the variable, it gives you an error message like the one you encountered.
You probably declare the variable as extern, but never actually declare it (un-extern-ly).
-
It's a little confusing what you are trying to do.
The extern keyword is simply introducing the name into the scope. However, this name has yet to be defined. No storage was yet allocated to it either. So your error is because of that. When the line int az = netClient.GetAzimuth(); is reached, netClient has not been defined yet.
The name inside the class has nothing to do with it, even though it has the same name.
-
You are trying to use the netClient variable that is a member of BMLDrawable? If so, then remove the entire declaration, the netClient variable is already declared as part of that class.
To use the netClient that is part of BMLDrawable, you have to be inside of a BMLDrawable member function. You posted "the line that is causing it." As long as that line is inside of a member function of BML drawable, you should be fine.
If you don't want to use the netClient that is part of the BMLDrawable class, then you need to remove the extern to create a global variable. Whether that's the best choice or not depends on the rest of your code, but it should help it compile and link.