C++;新手,获取编译错误(linux,g+;+;编译器) 我正在学习C++,我正在编写一个非常简单的程序。p>
我试着环顾一下网络,我不知道哪里出了问题,也不知道为什么错误是说我对各种变量有未定义的引用 我正在Linux上使用g++编译器 代码如下:C++;新手,获取编译错误(linux,g+;+;编译器) 我正在学习C++,我正在编写一个非常简单的程序。p>,c++,compiler-errors,compilation,C++,Compiler Errors,Compilation,我试着环顾一下网络,我不知道哪里出了问题,也不知道为什么错误是说我对各种变量有未定义的引用 我正在Linux上使用g++编译器 代码如下: #include <iostream> using namespace std; int main() { double celsius_temp, fahrenheit_temp; cout << "Input celsius temp:"; cin >> celsius_temp;
#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
#包括
使用名称空间std;
int main()
{
双摄氏温度,华氏温度;
温度>摄氏度;
华氏温度=(摄氏温度*1.8)+32;
无法使用g++
而不是gcc
编译。错误是链接器错误(它找不到函数引用)。gcc
也可以编译cpp
,但使用g++
而不是gcc
编译非常复杂。gcc
错误是链接器错误(它找不到函数引用).gcc
也可以编译cpp
,但它很复杂Add#include
您正在使用的g++的确切版本是什么?gcc convert.cpp-o convert
g++convert.cpp-o convert
可能与Add#include
您正在使用的g++的确切版本是什么?gcc convert.cpp-o convert
->g++convert.cpp-o convert
答案的可能重复项是正确的+1,但对他多解释一点会更好