LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Link error in LabWindows 7.0 Multithreading App

This is probably an easy one, but I've no experience with multithreading anything, and I'm stuck -

I'm getting link errors at every invocation of Get/Set/InitializeMyVariable in my code.

I have threethread safe variables, all declared in one header file, thusly -

DeclareThreadSafeVar(int, HaltProgramFlag);
DeclareThreadSafeVar(int, ShutdownProgramFlag);
DeclareThreadSafeVar(int, ShutdownDoneFlag);

which is included in each file that references them.

Each individual source file compiles without complaining, but when I build the project I get (for example) -

Undefined symbol '_InitializeShutdownProgramFlag' referenced in "Blahblah.c".
Undefined symbol '_GetShutdownProgramFlag' referenced in
"Blahblah.c".

So far all I've done is put in the declarations, calls to InitializeMyVariable in main, and a few instances of Get/SetMyVariable around the place.

Any/all help would be appreciated.

Thank you

Thomas McManus
0 Kudos
Message 1 of 6
(3,737 Views)
Check out this document for information about CVI's multithreading functions and examples.
You can also find some shipping examples on this under ..\CVI\samples\utility\Threading\

Compare your code to the code provided here and make sure everything is set up correctly.

I hope this helps

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 2 of 6
(3,737 Views)
Bilal -

Thanks for the pointers. I read through it and it really seems like everything is set up properly.

The problem with the Threading samples is that the Thread Safe Variables are created at a global scope within a single file using DefineThreadSafeVar(type, name). I'm trying to use the other declaration, DeclareThreadSafeVar(type, name), which, according to the documentation I've found, should be placed in a header that is then included in each source file that needs to reference that variables.

I've simplified this down to the following -

multithreading.h -

DeclareThreadSafeVar(int, MyVariable);

multithreading.c

#include
#include "multithreading.h"

(main, etc here)
{
InitializeMyVariable();

return 0;
}


This results in a linker error for an undefined reference to _InitializeMyVariable()

I can't think of what else to add, remove, or change.

Tom McManus
0 Kudos
Message 3 of 6
(3,737 Views)
Hello Thomas

You must use "DefineThreadSafeVar" in one c-file, because this macro
creates the variable. So, use DefineThreadSafeVar in your
multithreading.c file. In the multithreading.h file you use the
DeclareThreadSafeVar, so that you van use the variable in other module too.

Stephan

Thomas McManus schrieb:
> Bilal -
>
> Thanks for the pointers. I read through it and it really seems like
> everything is set up properly.
>
> The problem with the Threading samples is that the Thread Safe
> Variables are created at a global scope within a single file using
> DefineThreadSafeVar(type, name). I'm trying to use the other
> declaration, DeclareThreadSafeVar(type, name), which, according to the
> documentation I've found, should be placed in a head
er that is then
> included in each source file that needs to reference that variables.
>
> I've simplified this down to the following -
>
> multithreading.h -
>
> DeclareThreadSafeVar(int, MyVariable);
>
> multithreading.c
>
> #include
> #include "multithreading.h"
>
> (main, etc here)
> {
> InitializeMyVariable();
>
> return 0;
> }
>
> This results in a linker error for an undefined reference to
> _InitializeMyVariable()
>
> I can't think of what else to add, remove, or change.
>
> Tom McManus
0 Kudos
Message 4 of 6
(3,737 Views)
Stephan -

That's exactly the problem.

You just became my new personal hero.

Thank you very, very much.

Tom McManus
0 Kudos
Message 5 of 6
(3,737 Views)
I am happy that I can help you. Maybe next time I am searching for a
hero....

Stephan Gerhards

Thomas McManus schrieb:
> Stephan -
>
> That's exactly the problem.
>
> You just became my new personal hero.
>
> Thank you very, very much.
>
> Tom McManus
0 Kudos
Message 6 of 6
(3,737 Views)