linkage issue

S

Slavko Vorkapitch

In common.h

extern int currentLineNumber;
extern int currentNestingLevel;

In common.cpp
#incude "common.h"

int currentLineNumber = 0;
int currentNestingLevel = 0;

In buffer.cpp

#include "common.h"

char TSourceBuffer::GetLine(void)
{
extern int currentLineNumber;
extern int currentNestingLevel;

do stuff with currentLineNumber and currentNestingLevel..

g++ is complaining about undefined reference to these two variables.
Any help appreciated.

Thanks in advance,
El Squid
 
V

Victor Bazarov

Slavko said:
In common.h

extern int currentLineNumber;
extern int currentNestingLevel;

In common.cpp
#incude "common.h"

int currentLineNumber = 0;
int currentNestingLevel = 0;

In buffer.cpp

#include "common.h"

char TSourceBuffer::GetLine(void)
{
extern int currentLineNumber;
extern int currentNestingLevel;

do stuff with currentLineNumber and currentNestingLevel..

g++ is complaining about undefined reference to these two variables.
Any help appreciated.

Why do you feel the need to redeclare these in the function?

V
 
S

Sven Bauhan

Victor said:
Why do you feel the need to redeclare these in the function?

V
Why do you feel the need to declare global variables at all? Remember coding
C++ not C.

Sven
 
D

Default User

Sven said:
Why do you feel the need to declare global variables at all? Remember coding
C++ not C.


Why do you think global variables are a feature common to or restricted
to C programming?




Brian Rodenborn
 
S

Slavko Vorkapitch

I got around the likage issue by removing the common.cpp file and
initializing the 2 variables in the .h file. Currently I have a
another issue with using a C style function ina C++ file:

In error.h

void AbortTranslation(TAbortCode ac);

In error.cpp

void AbortTranslation(TAbortCode ac)
{
.....
.....
}

In list.cpp

#include "error.h"

some_function
{
AbortTranslation(..);
}

g++ is complaining about undefined reference to AbortTranslation.

Thanks in advance (again),
El Squid
 

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,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top