gcc编译C++文件的错误

在linux下编译c程序使用gcc,然而编译c++程序却需要使用g++,使用gcc编译c++程序会产生错误:undefined reference to `std::ios_base::Init::Init()。使用gcc -lstdc++编译选项就好。或者改用g++。

 

gcc编译C++文件的错误_第1张图片


[root@localhost GameDeal]# gcc -o main main.cpp -ldl
/tmp/ccG8cHL0.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x23): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccG8cHL0.o: In function `__tcf_0':
main.cpp:(.text+0x6c): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccG8cHL0.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld 返回 1
[root@localhost GameDeal]#

你可能感兴趣的:(ios,C++,function,gcc,reference,initialization)