【发布时间】:2016-12-30 04:26:30
【问题描述】:
您好有以下示例代码:
func.h - 函数的头文件
#include <vector>
#include <tuple>
using std::vector;
using std::tuple;
tuple <double,double> A(vector<int>& n);
func.cpp - 函数 cpp 文件
#include <iostream>
#include <vector>
#include <tuple>
using namespace std;
tuple <double,double> A(vector<int>& n)
{
double a1=n.size();
double a2=a1+0.5;
return make_tuple(a1,a2);
}
main.cpp - 主 cpp 文件
#include <iostream>
#include <vector>
#include <tuple>
#include "func.h"
using namespace std;
int main()
{
double a1,a2;
vector<int> n;
n.push_back(1);
n.push_back(2);
tie(a1,a2)=A(n);
return 0;
}
这在 Visual Studio 中编译得很好。
我在 Linux(gcc 版本 4.4.7 20120313 Red Hat 4.4.7-11)上编译它时遇到问题:
g++ -03 -std=c++0x main.cpp func.cpp -lm
它无法编译,我收到以下错误:
1. In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/array:35,from main.cpp:5:/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/c++0x_warning.h:31:2: error: #error This file requires compiler and library suppcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
2. ‘std::tuple’ has not been declared
3. expected constructor, destructor, or type conversion before ‘<’ token
任何有关如何处理此问题的指导都会有所帮助!
【问题讨论】:
-
4.4 版的 GCC 不能很好地支持 C++11,实际上几乎没有。如果可能,您应该将 GCC 更新到更高版本(现在升级到 6.2 版,完全支持 C++11 和 C++14,以及即将推出的大部分 C++17)。
-
然后使用 C++11 之前的功能,例如
std::pair或数组或结构。并使用其他环境来学习现代 C++。 -
在您自己 PC 的虚拟机中安装 modern GNU/Linux 发行版,例如 CentOS6 minimum(相当于 RedHat6)并放弃它在 1997 年(发布 RHEL4.x/5 年)继续被困的“服务器人”,恕我直言,这对您不利。
-
我编辑了您的原始命令 (
g++ -o -std=c++0x b main.cpp func.cpp -03 -lm),因为它有一些错误(错误的优化选项、未知的 b 文件、缺少 a 输出) -
@jarhead 我建议你学习使用 gcc。如果您留在软件中并且它是免费的,您可能会经常遇到它。考虑直接从源代码编译您自己的 gcc 版本...如果您有时间 ;)
标签: c++ linux gcc compilation