【发布时间】:2026-02-19 06:05:01
【问题描述】:
我正在尝试使用 Putty 在我的家用计算机上运行 Ubuntu 的服务器上编译 C++ 11 代码。我正在使用 makefile 编译并在代码中包含共享指针,但它给了我这个错误:
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
但是,当我尝试从托管文件的服务器编译代码时(当我在大学时),它编译得很好。这是我的makefile:
all: huffmandriver.o huffmannode.o huffmantree.o
g++ -o huffencode huffmandriver.o huffmannode.o huffmantree.o -std=c++11
huffmannode.o: huffmannode.cpp huffmannode.h
g++ -c huffmannode.cpp -std=c++11
huffmantree.o: huffmantree.cpp huffmantree.h
g++ -c huffmantree.cpp -std=c++11
clean:
@rm -f *.o
@rm -f huffencode
我也尝试添加标志-stdlib=libc++ -std=gnu++,但这也不起作用。这是引发错误的代码的 sn-p:
// Huffman Node class header
#ifndef HUFFMANNODE_H
#define HUFFMANNODE_H
#include <memory>
#include <string>
namespace YNGMAT005 {
class HuffmanNode {
private:
std::shared_ptr<HuffmanNode> left;
std::shared_ptr<HuffmanNode> right;
std::shared_ptr<HuffmanNode> parent;
std::string letter;
int frequency;
public:
HuffmanNode(std::string l, int freq);
~HuffmanNode();
std::shared_ptr<HuffmanNode> & get_left();
std::shared_ptr<HuffmanNode> & get_right();
std::shared_ptr<HuffmanNode> & get_parent();
void set_left(std::shared_ptr<HuffmanNode> & l);
void set_right(std::shared_ptr<HuffmanNode> & r);
bool has_left();
bool has_right();
void set_parent(std::shared_ptr<HuffmanNode> & p);
bool has_parent();
std::string get_letter();
int get_frequency();
};
}
#endif
非常感谢!
【问题讨论】:
-
你不能在这两种情况下都运行 'which g++' 和 'g++ --version' 来查看你使用的是哪个编译器(我假设是 g++)吗?
-
服务器使用g++(Ubuntu 4.8.4-2ubuntu1~14.04.3)4.8.4,“which g++”返回“/usr/bin/g++”。