1 Attachment(s)
How to link a static library struct to a user app ?
Using a struct object can be quite useful to combine several different data types into a single package. I have tried to do this utilizing a static library, but have run into problems. The main problem is to get the calling app to access the library struct. I have attached a small demo to illustrate the problem. Any help greatly appreciated. Thanks.
Re: How to link a static library struct to a user app ?
To use a global variable in more than one translation unit, declare it in a header using extern specifier...
Code:
// MyLib.h
// ...
extern sTensor g_tensor; // declaration
...and define it in an implementation file...
Code:
// MyLib.cpp
#include "stdafx.h"
#include "MyLib.h"
sTensor g_tensor; // definition
// ...
...or a little bit better, avoid global variables at all.
Or at least... as much as possible. :)
Also, it no hurts if throwing an eye in
Re: How to link a static library struct to a user app ?
Quote:
Originally Posted by
Mike Pliam
Using a struct object can be quite useful to combine several different data types into a single package. I have tried to do this utilizing a static library, but have run into problems. The main problem is to get the calling app to access the library struct.
Mike, structure is just a data type declaration. Header thing. It just cannot have anything to do with static library, as library is able to contain definitions (function bodies or global variables) but not declarations. Static library has nothing common with java packages or c# assemblies. When programming in C/C++ you'd better think in C/C++ and use proper terminology. Then it would be easier to isolate irrelevant aspects, and therefore, focus on your real issues.