473,395 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

linkage issue

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
4 1104
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: qazmlp | last post by:
const has internal linkage in C++, but external linkage in C. Am I right ? But, linker reports multiply-defined error if the following header is included in multiple .cpp files. //...
47
by: Richard Hayden | last post by:
Hi, I have the following code: /******************************** file1.c #include <iostream> extern void dummy(); inline int testfunc() {
20
by: Grumble | last post by:
Hello everyone, As far as I understand, the 'inline' keyword is a hint for the compiler to consider the function in question as a candidate for inlining, yes? What happens when a function with...
7
by: Generic Usenet Account | last post by:
I am implementing a library that can be linked in with C as well as C++ code. Obviously, the library API is functional, but in my implementation I am using STL. Because of this, my code is...
10
by: Mark A. Gibbs | last post by:
I have a question about mixing C and C++. In a C++ translation unit, I want to define a function with internal linkage and C calling convention. Here's a sample of what I want to do: //...
5
by: pembed2003 | last post by:
Hi all, I am reading the book "C How to Program" and in the chapter where it discuss scope rule, it says there are four scopes for a variable: function scope file scope block scope...
3
by: al.cpwn | last post by:
do static and inline functions or members have internal linkage? I have been reading this newsgroup on google and found conflicting ideas. Can someone please help me understand why in some places...
13
by: fctk | last post by:
source: http://rm-f.net/~orange/devel/specifications/c89-draft.html#3.1.2.2 there are two passages in this paragraph i can't fully understand: 1) "If the declaration of an identifier for an...
0
by: himnish | last post by:
hi, I'm trying to compile opensource snort-2.6.1.3 with HP-UX aCC compiler. While compiling I'm getting the issue like line 1589: error #3031-D: an entity with internal linkage cannot...
4
by: Bart Simpson | last post by:
I m getting a ton of linkage errors (unresolved externals) when using an abstract base class. My classes look something like this: class BaseObject { //pure virtuals virtual void foo() = 0;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.