MSVC++ 6.0 Linking problem (possible OT)

H

hamishd

TestClass.obj : error LNK2005: "int volatile bIsProcessing"
(?bIsProcessing@@3HC) already defined in OtherClass.obj

Creating library Release/TestDLL.lib and object Release/TestDLL.exp
Release/TestDLL.dll : fatal error LNK1169: one or more multiply defined
symbols found


In TestClass header file I have:
volatile BOOL bIsProcessing;

In OtherClass I have:
volatile BOOL * pbProcessing;

I cannot link, and I am confused as what is wrong? I can't see any
difference between this situation and one in a different project which
is linking ok
 
J

Jeff Partch

hamishd said:
TestClass.obj : error LNK2005: "int volatile bIsProcessing"
(?bIsProcessing@@3HC) already defined in OtherClass.obj

Creating library Release/TestDLL.lib and object Release/TestDLL.exp
Release/TestDLL.dll : fatal error LNK1169: one or more multiply defined
symbols found


In TestClass header file I have:
volatile BOOL bIsProcessing;

Is this maybe a global defined in the header and included in both?
 
V

Victor Bazarov

hamishd said:
TestClass.obj : error LNK2005: "int volatile bIsProcessing"
(?bIsProcessing@@3HC) already defined in OtherClass.obj

Creating library Release/TestDLL.lib and object Release/TestDLL.exp
Release/TestDLL.dll : fatal error LNK1169: one or more multiply
defined symbols found


In TestClass header file I have:
volatile BOOL bIsProcessing;

Never put definitions in the header, unless they are definitions of
functions declared 'inline'. Or definitions of classes. Or of class
templates. Or of function templates. Anyway, do not define *objects*
in headers.

What you probably want is

extern volatile BOOL bIsProcessing; // declaration

in the header and then

volatile BOOL bIsProcessing = false; // definition

in *one* of the C++ files.
In OtherClass I have:
volatile BOOL * pbProcessing;

I cannot link, and I am confused as what is wrong?

The linker already told you: multiple definition of an object.
I can't see any
difference between this situation and one in a different project which
is linking ok

What can I say? Look more carefully. There must be a difference.

V
 
H

hamishd

Never put definitions in the header, unless they are definitions of
functions declared 'inline'. Or definitions of classes. Or of class
templates. Or of function templates. Anyway, do not define *objects*
in headers.

What you probably want is

extern volatile BOOL bIsProcessing; // declaration

in the header and then

volatile BOOL bIsProcessing = false; // definition

in *one* of the C++ files.

Thanks. Got it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top