LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I use global variables from one dll in another (not multi-threaded)

Solved!
Go to solution

Using LabWindows/CVI. I'm trying to be compatible with legacy code, so this isn't the best way to do things but it saves me some headaches.

 

I have one project/.dll called "GlobalBlock" that contains certain parameters used widely throughout the program. The whole program consists of multiple dlls, for encapsulation purposes.

 

GlobalBlock.c contains:

 

struct menu_sdef G_setprefs =
{
//... stuff

};

struct sys_fileheader_sdef Level1Version =
{
//... more stuff

};

struct sys_flags_sdef G_sys_flags;

0 Kudos
Message 1 of 4
(3,506 Views)

Sorry, hit the wrong button.

 

GlobalBlock.h contains:

 

   #ifndef __GlobalBlock_C__
    extern struct menu_sdef              G_setprefs;
    extern struct sys_fileheader_sdef Level1Version;
    extern struct sys_flags_sdef        G_sys_flags;
 
   ...

   #endif

 

When I compile the second dll, Plots.c, the C code for which contains something like

 

   #include "GlobalBlock.h"

... 

G_setprefs.X = 1.23;

 

I get :

"undefined symbol '_G_setprefs' in Plots.c

"undefined symbol '_G_sys_flags' in Plots.c

 

The Build option to include the .h file in the library is set. 

 

I've searched the forums and the help files, and can't find any indication that I should be doing anything different.

 

0 Kudos
Message 2 of 4
(3,504 Views)
Solution
Accepted by topic author pblase

In the dll that owns the variable, use the _export qualifier on it. This will ensure that it is placed in the dll interface list. In the application (dll or otherwise) that wants to reference this variable, use the _import qualifier on it. This tells the system to use the associated import library that comes with the dll, in order to resolve the references at run time.

 

JR

0 Kudos
Message 3 of 4
(3,479 Views)

Thanks much.

Paul

0 Kudos
Message 4 of 4
(3,454 Views)