Collect2:错误:LD在C 中返回1个退出状态
collect2: error: ld returned 1 exit status in c++
我刚刚切换到基本操作系统并安装了Sublime Text Editor。我在C 中写了一个基本的Hello World程序来检查工作。我得到了这个错误。
/tmp/cc3Pmvft.o: In function `main':
source.cpp:(.text+0xa): undefined reference to `std::cout'
source.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*)'
source.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> >&)'
source.cpp:(.text+0x1c): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/tmp/cc3Pmvft.o: In function `__static_initialization_and_destruction_0(int, int)':
source.cpp:(.text+0x4a): undefined reference to `std::ios_base::Init::Init()'
source.cpp:(.text+0x59): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
Hello World节目是
#include <iostream>
using namespace std;
int main(){
cout << "Hello World!" << endl;
return 0;
}
我在Google和Stackoverflow中搜索了答案,但找不到解决方案。
您应该用C 编译器将其编译,而不是C,G 。
而不是这个
gcc source.cpp
做这个
g++ source.cpp
相关文章:
- 如何返回多个矢量对象的平均值?C++
- C++ 中的编译错误:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- 在 c++ 中,如何返回多个对象并从 RVO 中受益
- 编译问题:在函数"_start"中:未定义对"主"的引用 collect2:错误:ld 返回 1 个退出状态
- collect2:错误:ld 返回 1 个退出状态未定义的引用
- 返回两个向量 – 使用引用还是元组?
- PyTorch C++ 前端向前返回多个张量
- 为什么 getch 在按下函数或箭头键时返回三个值?
- 函数返回两个字符串的第一个常用字符
- 从递归函数 C++ 返回多个值
- C++函数返回两个 char 数组的相同索引元素
- FBX SDK 在预期 3 个顶点时返回 4 个顶点
- 使用函数的元组返回多个值的问题
- C++:如何使用传递引用在一个方法中返回多个值
- 为什么同一个逻辑方程在python和c++中返回两个不同的结果
- "Extern"对象问题:错误:Id 返回 1 个退出状态
- c++ (C::B) 错误:ld 返回 1 个退出状态
- 返回多个 py::数组而不在 pybind11 中复制
- 从 COM 接口中的函数返回多个值
- C++ 简单的掷骰子 - 如何返回多个不同的随机数