gpt4 book ai didi

c++ - 在 ubuntu shell 上编译 cpp 程序时出现问题

转载 作者:太空宇宙 更新时间:2023-11-04 09:21:21 24 4
gpt4 key购买 nike

<分区>

所以我尝试了 Linux C++ 编译器,这在编译以下代码时发生了:

#include <iostream> 
using namespace std;
int main(){
cout<<"Hello World!\n"<<endl;
return 0;
}



ceibal@ceibal:~$ gcc HelloWorld.cpp
/tmp/cc78Dkhk.o: In function `main':
HelloWorld.cpp:(.text+0xa): undefined reference to `std::cout'
HelloWorld.cpp:(.text+0xf): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
HelloWorld.cpp:(.text+0x14): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
HelloWorld.cpp:(.text+0x1c): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/cc78Dkhk.o: In function `__static_initialization_and_destruction_0(int, int)':
HelloWorld.cpp:(.text+0x4a): undefined reference to `std::ios_base::Init::Init()'
HelloWorld.cpp:(.text+0x4f): undefined reference to `std::ios_base::Init::~Init()'
collect2: ld devolvió el estado de salida 1
ceibal@ceibal:~$ pico HelloWorld.cpp
ceibal@ceibal:~$ gcc HelloWorld.cpp
HelloWorld.cpp:3:1: error: expected ‘;’ before ‘int’
ceibal@ceibal:~$ pico HelloWorld.cpp
ceibal@ceibal:~$ gcc HelloWorld.cpp
/tmp/ccIivRal.o: In function `main':
HelloWorld.cpp:(.text+0xa): undefined reference to `std::cout'
HelloWorld.cpp:(.text+0xf): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
HelloWorld.cpp:(.text+0x14): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
HelloWorld.cpp:(.text+0x1c): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccIivRal.o: In function `__static_initialization_and_destruction_0(int, int)':
HelloWorld.cpp:(.text+0x4a): undefined reference to `std::ios_base::Init::Init()'
HelloWorld.cpp:(.text+0x4f): undefined reference to `std::ios_base::Init::~Init()'
collect2: ld devolvió el estado de salida 1

我尝试使用相同的程序,但在 C 上它运行得很好,但是当我将它翻译成 C++ 时,就发生了这种情况。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com