473,463 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

strange link problem

Hello,

I got a strange link problem; here are the simplest files showing the
error:

a.h::
#include <utility>

class a{
public:
typedef int perm;
static const perm PERM_NONE = 0;
a();
private:
std::pair<int, perm> aaa;
};

a.cpp::
#include "a.h"
a::a() : aaa(0,PERM_NONE) { }
main () { }

Compiling with g++ (GCC) 3.3.5 (Debian 1:3.3.5-13) I get::

$ g++ a.cpp
/tmp/ccKKUXg8.o: In function
`a::a[not-in-charge]()':a.cpp:(.text+0xa): undefined reference to
`a::PERM_NONE'
/tmp/ccKKUXg8.o: In function `a::a[in-charge]()':a.cpp:(.text+0x34):
undefined reference to `a::PERM_NONE'
collect2: ld returned 1 exit status

The file compiles correctly, the error shows up only when linking.

What could it possibly be? Thanks for any help!

Arcimboldo

Mar 7 '06 #1
4 1638
> What could it possibly be?

What if you delete the 'static' keyword?
What if you construct aaa not in the list but in the
compound statement "{}" of the constructor?

My guess is that the static var is not yet initialized when a::a() :
aaa(0,PERM_NONE) { } is called.

Marc Wentink

Mar 7 '06 #2
The problem is because static data members need to be defined exactly
once in every translation unit. Please see
http://www.parashift.com/c++-faq-lit...html#faq-10.11

Regards,

Ryan Mansfield

Mar 7 '06 #3
rm********@gmail.com wrote:
The problem is because static data members need to be defined exactly
once in every translation unit.


Nope! Static data members have to be defined exactly once in the
whole program. The only exception are constant integral expressions
whose address is never taken: these don't need any definition.
However, addresses are easily taken, e.g. by passing the value to a
function taking an 'int const&' as parameter. The best bet for a
constant integral expression which does not need a separate
definition is using an enum.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Mar 7 '06 #4

ar********@gmail.com wrote:
Hello,

I got a strange link problem; here are the simplest files showing the
error:

a.h::
#include <utility>

class a{
public:
typedef int perm;
static const perm PERM_NONE = 0;
a();
private:
std::pair<int, perm> aaa;
};

a.cpp::
#include "a.h"
a::a() : aaa(0,PERM_NONE) { } try a::a(): aaa(0, a::PERM_NONE){} main () { }

Compiling with g++ (GCC) 3.3.5 (Debian 1:3.3.5-13) I get::

$ g++ a.cpp
/tmp/ccKKUXg8.o: In function
`a::a[not-in-charge]()':a.cpp:(.text+0xa): undefined reference to
`a::PERM_NONE'
/tmp/ccKKUXg8.o: In function `a::a[in-charge]()':a.cpp:(.text+0x34):
undefined reference to `a::PERM_NONE'
collect2: ld returned 1 exit status

The file compiles correctly, the error shows up only when linking.

What could it possibly be? Thanks for any help!

Arcimboldo


Mar 7 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: M O J O | last post by:
Hi, I'm developing a asp.net application and ran into a strange css problem. I want all my links to have a dashed underline and when they are hovered, it must change to a solid line. Sounds...
4
by: Gav | last post by:
Hi all, I'm having this strange problem where, in a web app, I have 2 different links to a different form. One is just a straight forward link the other is a bit more complicated because it gets...
7
by: M O J O | last post by:
Hi, I'm developing a asp.net application and ran into a strange css problem. I want all my links to have a dashed underline and when they are hovered, it must change to a solid line. Sounds...
0
by: riteshjain1982 | last post by:
Pagepostback.....strange problem Hi, I am at cient place and getting very strange problem with my asp.net application............when i call my web application from any desktop machine in lan...
0
by: maryjones11289 | last post by:
Hi, I have a strange problem that hopefully someone can advise me on... I have a Gridview which is not bound to a dataset etc. I populate the gridview manually by constructing my own table,...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
1
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.