百度问答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个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询