C++新手,得到编译错误(Linux,G ++编译器)
C++ newbie, getting compile error (linux, g++ compiler)
我只是在学习C++,我正在尝试编译一个非常简单的程序。
我尝试在网上查看,但我不知道出了什么问题,也不知道为什么错误说我对各种变量有未定义的引用。
我在Linux上使用g++编译器。
这是代码:
#include <iostream>
using namespace std;
int main()
{
double celsius_temp, fahrenheit_temp;
cout << "Input celsius temp:";
cin >> celsius_temp;
fahrenheit_temp = (celsius_temp * 1.8) + 32;
cout << "Fahrenheit temp is:" << fahrenheit_temp;
return 0;
}
这是输入的命令和错误:
$ gcc convert.cpp -o convert
/tmp/ccTjTVCH.o: In function `main':
convert.cpp:(.text+0x1d): undefined reference to `std::cout'
convert.cpp:(.text+0x22): 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*)'
convert.cpp:(.text+0x2e): undefined reference to `std::cin'
convert.cpp:(.text+0x33): undefined reference to `std::istream::operator>>(double&)'
convert.cpp:(.text+0x5f): undefined reference to `std::cout'
convert.cpp:(.text+0x64): 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*)'
convert.cpp:(.text+0x7c): undefined reference to `std::ostream::operator<<(double)'
/tmp/ccTjTVCH.o: In function `__static_initialization_and_destruction_0(int, int)':
convert.cpp:(.text+0xbe): undefined reference to `std::ios_base::Init::Init()'
convert.cpp:(.text+0xcd): undefined reference to `std::ios_base::Init::~Init()'
collect2: error: ld returned 1 exit status
使用 g++
而不是 gcc
进行编译。错误是链接器错误(它找不到函数引用(。 gcc
也可以编译cpp
但很复杂
相关文章:
- 在 Azure DevOps 构建管道中使用英特尔C++编译器为 Linux 环境构建C++代码
- std矢量内存分配linux与windows编译器
- Qt Creator在linux mint 64位中找不到CMAKE_CXX_COMPILER编译器
- 如何在没有编译器的情况下在 Linux 上安装 gcc
- 我可以让我的本地C 编译器与Linux环境中的编译器不同吗?
- C++新手,得到编译错误(Linux,G ++编译器)
- GCC 编译器对类型转换有什么作用?为什么 mac 和 Linux 上的输出不同
- 一个C++编译器是为不同的平台(Linux,Windows等)多次编写的,这是真的吗?
- Linux Opensuse C 编译器问题.(无法初始化部分调试器的解压缩状态)
- 在英特尔C++编译器 (Linux) 的配置搜索路径中找不到文件可执行文件
- 在putty上使用g++编译器进行编译会将我的代码传递到linux服务器吗
- MATLAB在MEX_COLPILE LINUX中找到没有支持的编译器或SDK
- 如何更改Linux CentOS上的MPI使用的默认GCC编译器
- 如何使用Arm-Linux-androideabi编译器
- 我的程序在Windows上使用MSVC和G 编译器运行,但在Linux上不运行
- 非常量引用类型的无效初始化中出错.在Linux操作系统中使用c++代码.GCC编译器
- 内存对齐 - Sparc(Sun) cc 编译器、Intel(Linux) g++ 编译器、Intel(Windows)
- 使用linux g++编译器在makefile中创建静态库
- 使用Linux编译器时出现错误但失去意义
- Linux C++编译器(和链接器)如何决定将typeinfo放在哪里