EmbDev.net

Forum: ARM programming with GCC/GNU tools iostream - related linker error (GNU/Linux Compiler g++)


von Asim (Guest)


Rate this post
useful
not useful
Hi,

I am getting following linker errors using g++

***`__static_initialization_and_destruction_0'
***iostream:76: undefined reference to `std::ios_base::Init::Init()'
***iostream:76: undefined reference to `std::ios_base::Init::~Init()'

GNU/Linux using g++

.\Objects\main.o: In function 
`__static_initialization_and_destruction_0':

/cygdrive/c/Hitex/GnuToolPackageArm/bin/../lib/gcc/arm-hitex-elf/4.1.1/. 
./../../../include/c++/4.1.1/iostream:76:  undefined reference to 
`std::ios_base::Init::Init()'

/cygdrive/c/Hitex/GnuToolPackageArm/bin/../lib/gcc/arm-hitex-elf/4.1.1/. 
./../../../include/c++/4.1.1/iostream:76:  undefined reference to 
`std::ios_base::Init::~Init()'

It is a very simple C++ code which is not using any special C++ 
features.
The code compiles,links and runs fine when <iostream> is "NOT" included 
in the main.cpp file.

but as soon as <iostream> is included in the main.cpp file, the code 
compiles, but the above linker error is generated.

Any help is appreciated!!!
Thanks!

von Rolf Magnus (Guest)


Rate this post
useful
not useful
> GNU/Linux using g++

Sure about that? Your paths look like this is Windows/Cygwin.

What's you compiler/linker command line?

von Asim S. (asim)


Rate this post
useful
not useful
arm-hitex-elf-g++ -mcpu=arm7tdmi -c -gdwarf-2 -xc -MD -Wall -O0 
-mthumb-interwork -mapcs-frame  -fsigned-char  -mlittle-endian  -marm
 -I.\Source\  -I.\ -o .\Objects\interrupt.o 
.\Source\System\interrupt.cpp

arm-hitex-elf-as -mcpu=arm7tdmi  -gdwarf2  -mthumb-interwork
-I.\Source\  -I.\ -o .\Objects\startup.o .\Source\System\startup.s

arm-hitex-elf-g++ -mcpu=arm7tdmi  -c -gdwarf-2 -xc++  -Wall -O0 
-mthumb-interwork -mapcs-frame  -fsigned-char  -mlittle-endian  -marm
 -I.\Source\  -I.\ -o .\Objects\main.o .\main.cpp

arm-hitex-elf-ld  -T.\Settings\main.ld.tmp --cref -t -static 
-nostartfiles -Map=.\DOC\DemoC++.map  -stats -lhcclib -lc -lgcc -lm
-o .\Objects\DemoC++.elf

.\Objects\main.o: In function 
`__static_initialization_and_destruction_0':
/cygdrive/c/Hitex/GnuToolPackageArm/bin/../lib/gcc/arm-hitex-elf/4.1.1/. 
./../../../include/c++/4.1.1/iostream:76:  undefined reference to 
`std::ios_base::Init::Init()'

/cygdrive/c/Hitex/GnuToolPackageArm/bin/../lib/gcc/arm-hitex-elf/4.1.1/. 
./../../../include/c++/4.1.1/iostream:76:  undefined reference to 
`std::ios_base::Init::~Init()'


arm-hitex-elf-ld: link errors found, deleting executable 
`.\Objects\DemoC++.elf'
arm-hitex-elf-ld: mode armelf
.\Objects\interrupt.o (3kb)
.\Objects\startup.o (6kb)
.\Objects\main.o (35kb)

von Andreas F. (aferber)


Rate this post
useful
not useful
Asim Shaikh wrote:
> arm-hitex-elf-ld  -T.\Settings\main.ld.tmp --cref -t -static
> -nostartfiles -Map=.\DOC\DemoC++.map  -stats -lhcclib -lc -lgcc -lm
> -o .\Objects\DemoC++.elf

You are not linking against the C++ runtime (libstdc++), which would 
provide you with your missing symbols.

It is recommended to use g++ itself (arm-hitex-elf-g++ in your case) for 
linking. This ensures that all necessary runtime libraries are included 
automatically. If you want to provide parameters to the linker itself 
(like -nostartfiles or -Map in your case), you can do this using the 
"-Wl,..." parameter to g++, for example "-Wl,-nostartfiles".

Andreas

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.