为什么c++标准库不能工作?

Why is the c++ standard library not working?

本文关键字:工作 不能 c++ 标准 为什么      更新时间:2023-10-16

我一直试图让我的程序,我从我的学校服务器下载到我的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工具链

相关文章: