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

Guest #1700969
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!
Guest #1701402
> GNU/Linux using g++

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

What's you compiler/linker command line?
#1701427
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
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

A question of your own? This thread is over 16 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

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.