[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
undefined error message for static variable during link phase
From: |
jk |
Subject: |
undefined error message for static variable during link phase |
Date: |
Sat, 29 Jan 2005 23:46:05 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7) Gecko/20040616 |
struggling with C++ I run into an error which I do not understand.
see the attached files
the static variable foo1 is being declared undefined during link phase.
the various messages are in File undefErrMsg.txt
I have an example from "goto Objekt Orientierung" by Herold/Klar/Klar
(Addison Wesley) which exactly allows this kind of use of a "static"
variable
--
================= lat=52.35°N - lon=10.25°E ======================
http://www.ibk-consult.de
kampmann@ibk-node14:/home/kampmann/tests/cpp->make undefind
g++ undefind.cc -o undefind
kampmann@ibk-node14:/home/kampmann/tests/cpp->undefind
foo1 = 1
kampmann@ibk-node14:/home/kampmann/tests/cpp->cp undefind.cc undefStatic.cc
kampmann@ibk-node14:/home/kampmann/tests/cpp->make undefStatic
g++ undefStatic.cc -o undefStatic
/tmp/cc2aNvzh.o(.text+0x5): In function `CFoo::CFoo[not-in-charge]()':
: undefined reference to `CFoo::foo1'
/tmp/cc2aNvzh.o(.text+0x15): In function `CFoo::CFoo[in-charge]()':
: undefined reference to `CFoo::foo1'
/tmp/cc2aNvzh.o(.text+0x51): In function `main':
: undefined reference to `CFoo::foo1'
collect2: ld returned 1 exit status
make: *** [undefStatic] Error 1
kampmann@ibk-node14:/home/kampmann/tests/cpp->make undefStatic
g++ undefStatic.cc -o undefStatic
/tmp/cc0unNKD.o(.text+0x37): In function `CFoo::loadFoo(int)':
: undefined reference to `CFoo::foo1'
/tmp/cc0unNKD.o(.text+0x6f): In function `main':
: undefined reference to `CFoo::foo1'
collect2: ld returned 1 exit status
make: *** [undefStatic] Error 1
kampmann@ibk-node14:/home/kampmann/tests/cpp->cp undefStatic.cc undefInline.cc
kampmann@ibk-node14:/home/kampmann/tests/cpp->make undefInline
g++ undefInline.cc -o undefInline
/tmp/ccMSAGs6.o(.text+0x7): In function `CFoo::loadFoo(int)':
: undefined reference to `CFoo::foo1'
/tmp/ccMSAGs6.o(.text+0x3f): In function `main':
: undefined reference to `CFoo::foo1'
collect2: ld returned 1 exit status
make: *** [undefInline] Error 1
// file: undefInline.cc
//
#include <stdio.h>
class CFoo{
public:
static int foo1 ;
void loadFoo( int ) ;
CFoo() {
loadFoo( 1 ) ;
}
~CFoo() ;
} ;
void CFoo::loadFoo( int aa ) {
foo1 = aa ;
}
CFoo::~CFoo(){}
main(){
CFoo foo ;
printf( "foo1 = %d\n", foo.foo1 ) ;
}
#include <stdio.h>
class CFoo{
public:
static int foo1 ;
CFoo() ;
~CFoo() ;
void loadFoo( int ) ;
} ;
CFoo::CFoo(){
loadFoo( 1 ) ;
}
void CFoo::loadFoo( int aa ) {
foo1 = aa ;
}
CFoo::~CFoo(){}
main(){
CFoo foo ;
printf( "foo1 = %d\n", foo.foo1 ) ;
}
#include <stdio.h>
class CFoo{
public:
int foo1 ;
CFoo() ;
~CFoo() ;
} ;
CFoo::CFoo(){
foo1 = 1 ;
}
CFoo::~CFoo(){}
main(){
CFoo foo ;
printf( "foo1 = %d\n", foo.foo1 ) ;
}
- undefined error message for static variable during link phase,
jk <=