小编Tzi*_*kos的帖子

为什么在使用 gcc 编译一个简单的 C++ 程序时会出现“未定义的引用”错误?

我尝试在 Ubuntu 中编译 C++。我在 Gedit 中编写代码,这是一个简单的 hello world 项目。我去终端运行它gcc helloworld.cc并弹出此消息:

/tmp/ccy83619.o: In function `main':
helloworld.cc:(.text+0xa): undefined reference to `std::cout'
helloworld.cc:(.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*)'
/tmp/ccy83619.o: In function `__static_initialization_and_destruction_0(int, int)':
helloworld.cc:(.text+0x3d): undefined reference to `std::ios_base::Init::Init()'
helloworld.cc:(.text+0x4c): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

这是什么意思,我该往哪里去?

compiling gcc c++

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×1

compiling ×1

gcc ×1