iostream - related linker error (GNU/Linux Compiler g++)

Guest #1700969
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!
#1701427
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)
#1701589
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

Reply

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.