LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Thread-Safe Variables - Multiple definitions for symbol at link time

Solved!
Go to solution

I am going through the "Multithreading in LabWindows/CVI" tutorial.

 

The following line is in the tutorial regarding Thread-Safe variables:

 

"If you need to access the thread-safe variable from more than one source file, use the DeclareThreadSafeScalarVar or DeclareThreadSafeArrayVar macro in an include (.h) file to create declarations for the accessor functions."

 

Works OK with one source file, but when I include the header file in a second source file I get "Multiple definitions for symbol" errors at link time for all the accessor functions in both source files.

 

It's probably something simple, but after couple hours I'm at a loss. Any ideas are appreciated.

 

Scott T

0 Kudos
Message 1 of 3
(3,090 Views)
Solution
Accepted by Scott_T

You should have DefineThreadSafeXXX in exactly ONE source file and a corresponding DeclareThreadSafeXXX in any number of source files (or in a header file included in any source files). The following works for me in CVI 2012:

 

/* temp.h */

#include <utility.h>

DeclareThreadSafeScalarVar(double, Num);

void test(void);

 

/*temp.c */

#include "temp.h"

DefineThreadSafeScalarVar(double, Num, -1);

void main(void) {

  InitializeNum();

  test();

}

 

/* temp2.c */

#include "temp.h"

void test(void) {

  SetNum(1.0);

}

 

Message 2 of 3
(3,083 Views)

Thanks, just what I needed.

0 Kudos
Message 3 of 3
(3,069 Views)