为什么c++标准库不能工作?
Why is the c++ standard library not working?
我一直试图让我的程序,我从我的学校服务器下载到我的mac上离线运行。我尝试通过以下教程更新GCC,由于某种原因,教程没有工作,即使我使用的命令。
现在当我编译…我得到一个错误,说没有找到…我不明白。我已经更新了Xcode..跟随了大量的教程…但我还是不能让它运转起来!
为什么说没有找到random,导致致命错误?
感谢错误:
DungeonLevel.h:6:10: fatal error: 'random' file not found
"由于这是一个编码网站,我需要提供代码,因为我可能忘记包含头文件…"
#ifndef _DungeonLevel_included_
#define _DungeonLevel_included_
#include "Tile.h"
#include <vector>
#include <random>
class Player;
class DungeonLevel {
public:
DungeonLevel(int iWidth, int iHeight, std::mt19937 & randomGen);
~DungeonLevel(void);
void dump();
char at(int x, int y);
Creature * removeCreature(Creature * creatureToRemove);
void moveCreature(Creature * creatureToMove, char dir);
void placeInGame(Creature * creatureToPlace, std::mt19937 & randomGen);
void placeInGame(Creature & creatureToPlace, std::mt19937 & randomGen);
Tile & returnTile(int x,int y);
int getWidth();
int getHeight();
private:
std::vector<std::vector<Tile>> m_vvTiles; //Tile was char
};
#endif
这是我的makefile:OBJECTS = Ammunition.o Armor.o Consumable.o Creature.o Entity.o Gold.o Item.o parser.o Potion.o Scroll.o Weapon.o XMLSerializable.o CreatureFactory.o DungeonLevel.o Player.o Tile.o ItemFactory.o
HEADERS = Ammunition.h Armor.h Consumable.h Creature.h Entity.h Gold.h Item.h parser.h Potion.h Scroll.h Weapon.h XMLSerializable.h CreatureFactory.h DungeonLevel.h Player.h Tile.h ItemFactory.h
all: Jhack
%.o: %.cpp $(HEADERS)
clang++ -c $< -o $@ -std=c++11 -stdlib=libc++
Jhack: $(OBJECTS) main.o
clang++ -o Jhack $^ -stdlib=libc++
clean:
rm -f *.o Jhack
run: Jhack
./Jhack
苹果的gcc真的过时了。尝试使用clang和libc++来构建,而不是使用gcc和libstdc++。编译标志:-std=c++11 -stdlib=libc++
,链接标志:-stdlib=libc++
。使用clang++代替g++。
编辑:请注意,您需要安装最新的命令行工具才能使其工作。
打开XCode。打开"Xcode"->"Preferences…"->"下载"选项卡。选择"命令行工具"并安装它们。如果它说它已安装-检查更新通过点击"检查和安装现在"按钮。
然后在终端输入clang++ --version
,你应该会看到如下内容:
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.3.0
Thread model: posix
Edit 2:如果这没有帮助,你仍然有一个过时的编译器版本。尝试在make文件中使用xcrun clang++
而不是clang++
。这将使用xcode工具链
相关文章:
- 为什么 HeapFree() 不能正常工作?
- std::unique_ptr 在 GCC 中工作,但不能在 Visual Studio 中编译
- 声明C++具有动态大小的数组类型在 Linux 中工作正常,但不能在 Windows 中工作
- 为什么"std::is_function_v"不能按预期工作?
- 为什么在C++中使用关系运算符创建的模板函数不能对字符串正常工作?
- std::remove() 按预期处理文字,但不能与取消引用的迭代器一起工作
- C++自定义删除运算符不能正常工作?
- 为什么使用 exec() 重新启动程序不能正常工作?
- C++:返回本地对象,但不能正常工作
- 有没有办法关闭文件? fclose 不能很好地工作
- 为什么我不能声明一个 constexpr 本地,而一个 const 一个工作?
- ostream_iterator运算符=在pair<int,int>上失败,但在包装器类上工作。我不能为成对<>重载运算符<<吗?
- 为什么带lcov的codecov在Travis上不能正常工作,而在我当地的Linux Mint上却不能正常工作
- 为什么sizeof函数在这里不能正常工作
- 为什么 decltype(declval()<T>.func()) 可以工作,而 decltype(&T::func) 不能工作?
- 静态 constexpr 函数在模板结构中工作,但不能在结构中工作.为什么?
- 为什么这个base64解码/编码功能不能正常工作?
- 为什么带有 const 关键字的构造函数可以工作,而没有它就不能工作?
- 如果 (QString.contains()) 不能正常工作,请使用 temp bool 变量进行更正
- 你不能在 void 指针上使用指针算法,那么 void 指针数组是如何工作的呢?