By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,148 Members | 1,346 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,148 IT Pros & Developers. It's quick & easy.

linkage issue

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Slavko Vorkapitch wrote:
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
Jul 22 '05 #2

P: n/a
Victor Bazarov wrote:

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

Jul 22 '05 #3

P: n/a
Sven Bauhan wrote:

Victor Bazarov wrote:

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.

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


Brian Rodenborn
Jul 22 '05 #4

P: n/a
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
Default User <fi********@boeing.com.invalid> wrote in message news:<41***************@boeing.com.invalid>...
Sven Bauhan wrote:

Victor Bazarov wrote:

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.

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


Brian Rodenborn

Jul 22 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.