为什么c ++标准库不工作? [英] Why is the c++ standard library not working?

查看:114
本文介绍了为什么c ++标准库不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图获取我从学校服务器下载的程序,以便在我的Mac上离线运行。我试图更新GCC通过以下教程和某些原因教程没有工作,即使我使用的命令给定。

I've been trying to get my program that I downloaded from my schools server to run offline on my mac. I tried updating GCC by following tutorials and for some reason the tutorials didn't work even though I was using the commands given.

现在当我编译..我得到一个错误说没有找到..我不明白。我已经更新了Xcode ..跟随吨的教程..我还是不能得到的东西运行!

Now when I compile.. I get an error saying that is not found.. I don't get it. I've updated Xcode.. followed tons of tutorials.. and I still can't get the thing to run!

为什么说,找不到随机,造成致命错误?

Why is it saying that random is not found, causing a fatal error?

感谢

DungeonLevel.h:6:10: fatal error: 'random' file not found



因为这是一个编码网站,我需要提供代码,因为我可能忘了包括头文件...



"Since this is a coding site, I need to provide code because I probably forgot to include a header file..."

#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:



Here's my 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 - >首选项... - >下载选项卡。选择命令行工具并安装它们。如果它说它已安装 - 通过单击立即检查并立即安装按钮检查更新。

之后类型 clang ++ --version 在终端中,您应该看到类似下面的内容:

Apple's gcc is really outdated. Try to build using clang and libc++ instead of gcc and libstdc++. Compile flags: -std=c++11 -stdlib=libc++, link flag: -stdlib=libc++. Use clang++ instead of g++.

Edit: note that you need to install latest command line tools for this to work.
Open XCode. Go to "Xcode" -> "Preferences..." -> "Downloads" tab. Select "Command Line Tools" and install them. If it says that it is installed - check for updates by clicking on "Check and Install Now" button.
After that type clang++ --version in terminal and you should see something like next:

Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.3.0
Thread model: posix

编辑2 :如果这没有帮助,并且仍然有一个过时的编译器版本。尝试在您的makefile中使用 xcrun clang ++ 而不是 clang ++ 。这将使用xcode工具链。

Edit 2: if that didn't help and you still have an outdated version of compiler. Try to use xcrun clang++ instead of clang++ in your makefile. That will use xcode toolchain.

这篇关于为什么c ++标准库不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆