百度问答linux Ubuntu 下用GCC编译“HELLO WORLD “出现错误。如下所示 5
#include<iostream>usingnamespacestd;intmain(){cout<<"HELLOWORLD"<<endl;return0;}结果如下:...
#include<iostream>
using namespace std;
int main()
{
cout<<"HELLO WORLD"<<endl;
return 0;
}
结果如下:
ymy@ymy-ubuntu:~/ctest$ gcc -o shi shi.cpp
/tmp/ccG7Dx59.o: In function `main':
shi.cpp:(.text+0xa): undefined reference to `std::cout'
shi.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*)'
shi.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> >&)'
shi.cpp:(.text+0x1c): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/tmp/ccG7Dx59.o: In function `__static_initialization_and_destruction_0(int, int)':
shi.cpp:(.text+0x4a): undefined reference to `std::ios_base::Init::Init()'
shi.cpp:(.text+0x59): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
ymy@ymy-ubuntu:~/ctest$
这是为什么? 展开
using namespace std;
int main()
{
cout<<"HELLO WORLD"<<endl;
return 0;
}
结果如下:
ymy@ymy-ubuntu:~/ctest$ gcc -o shi shi.cpp
/tmp/ccG7Dx59.o: In function `main':
shi.cpp:(.text+0xa): undefined reference to `std::cout'
shi.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*)'
shi.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> >&)'
shi.cpp:(.text+0x1c): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/tmp/ccG7Dx59.o: In function `__static_initialization_and_destruction_0(int, int)':
shi.cpp:(.text+0x4a): undefined reference to `std::ios_base::Init::Init()'
shi.cpp:(.text+0x59): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
ymy@ymy-ubuntu:~/ctest$
这是为什么? 展开
3个回答
启帆信息
2024-11-19 广告
2024-11-19 广告
启帆信息是英伟达中国区代理商,原厂授权代理,提供全面的软件技术解决方案以及NVIDIA以太网产品、交换机等产品,欢迎前来咨询!...
点击进入详情页
本回答由启帆信息提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询