问题
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.
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?
Thanks
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
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
回答1:
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
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.
来源:https://stackoverflow.com/questions/16229297/why-is-the-c-standard-library-not-working