【发布时间】:2021-04-26 11:44:13
【问题描述】:
当我尝试使用 gcc 或 clang 而不是 g++ 构建 cpp 代码时,为什么会失败? 使用 gcc 或 clang 我得到未定义的引用错误,但 g++ 没有错误
这是我的简单程序:
#include <iostream>
using namespace std;
int main() {
cout << "Hello World!" << endl;
return 0;
}
➜ clang main.cpp
/bin/x86_64-unknown-linux-gnu-ld: /tmp/main-986467.o: 在函数main': main.cpp:(.text+0x11): undefined reference to std::cout'
➜ gcc main.cpp -o myProg
/bin/ld: /tmp/ccJjbZYp.o: 警告:针对_ZSt4cout' in read-only section .text' 重定位/bin/ld: /tmp/ccJjbZYp.o: 在函数main': main.cpp:(.text+0xe): undefined reference to std::cout'中
【问题讨论】: