私の MacBook のデフォルトは GNU 4.7.1 です。学校のサーバーでプログラムを実行すると、大量のセグメンテーション違反が発生し続けます。学校のサーバーからプログラムの現在の状態をダウンロードして、NetBeans を使用してデバッグを支援できるようにしました。私の MacBook がデフォルトとして設定し続けていた古いバージョンの 4.2 を新しい GNU に置き換えるには、たくさんの問題に遭遇しました。
OSX コンパイラは私にとってまったく新しいものであり、学校のサーバーにあるようにすべてをコンパイルするようにメイクファイルを調整することはできません。
gcc または g++ を使用するように言われましたが、それは問題ではないと言う人もいました。私が理解していることから、OSX は新しいバージョンの GNU for c/c++ にさまざまなライブラリを使用していますが、現在は Clang が標準ですか? CSクラスでGNU/GCCを使用してきたという理由だけで、GNU/GCCに固執したいと思います。
現在、makefile が "std::mt19937" をリンクしようとすると、それをリンクするヘッダーが見つからないようです。
私の質問は、std::mt19937 と c++11 ライブラリの両方が使用されるように、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
# I tried this and adding $(LIBS) where "-std=c++0x" is below..
# LIBS = -std=c++0x -std=c++11 -std=gnu++11
%.o: %.cpp $(HEADERS)
gcc -c $< -o $@ -std=c++0x
Jhack: $(OBJECTS) main.o
gcc -o Jhack $^
clean:
rm -f *.o Jhack
run: Jhack
./Jhack
-std=c++11 と -std=gnu++11 の "-std=c++0x" を交換してみました。また、両方を追加してみました。また、gcc を g++ に交換しようとしましたが、試したり変更したりすると、エラーや警告がさらに発生します。
以下は、現在のエラー メッセージの最初の部分です (延々と続く)。
gcc -c Ammunition.cpp -o Ammunition.o -std=c++0x
gcc -c Armor.cpp -o Armor.o -std=c++0x
gcc -c Consumable.cpp -o Consumable.o -std=c++0x
gcc -c Creature.cpp -o Creature.o -std=c++0x
gcc -c Entity.cpp -o Entity.o -std=c++0x
gcc -c Gold.cpp -o Gold.o -std=c++0x
gcc -c Item.cpp -o Item.o -std=c++0x
gcc -c parser.cpp -o parser.o -std=c++0x
gcc -c Potion.cpp -o Potion.o -std=c++0x
gcc -c Scroll.cpp -o Scroll.o -std=c++0x
gcc -c Weapon.cpp -o Weapon.o -std=c++0x
gcc -c XMLSerializable.cpp -o XMLSerializable.o -std=c++0x
gcc -c CreatureFactory.cpp -o CreatureFactory.o -std=c++0x
gcc -c DungeonLevel.cpp -o DungeonLevel.o -std=c++0x
gcc -c Player.cpp -o Player.o -std=c++0x
gcc -c Tile.cpp -o Tile.o -std=c++0x
gcc -c ItemFactory.cpp -o ItemFactory.o -std=c++0x
gcc -c main.cpp -o main.o -std=c++0x
gcc -o Jhack 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 main.o
ld: warning: ignoring file Creature.o, file was built for unsupported file format ( 0x7f 0x45 0x4c 0x46 0x 2 0x 1 0x 1 0x 0 0x 0 0x 0 0x 0 0x 0 0x 0 0x 0 0x 0 0x 0 ) which is not the architecture being linked (x86_64): Creature.o
Undefined symbols for architecture x86_64:
"Creature::removeMonster(DungeonLevel&)", referenced from:
vtable for Player in Player.o
"Creature::dumpObjectData()", referenced from:
Player::dumpObjectData() in Player.o
"Creature::setElementData(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from:
Player::setElementData(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >) in Player.o
"Creature::writeDataAsFragment(std::basic_ostream<char, std::char_traits<char> >&)", referenced from:
Player::writeDataAsFragment(std::basic_ostream<char, std::char_traits<char> >&) in Player.o
"Creature::move(DungeonLevel&, Creature&, std::mersenne_twister_engine<unsigned int, 32ul, 624ul, 397ul, 31ul, 2567483615u, 11ul, 4294967295u, 7ul, 2636928640u, 15ul, 4022730752u, 18ul, 1812433253u>&)", referenced from:
vtable for Player in Player.o
"Creature::getHP()", referenced from:
vtable for Player in Player.o
_main in main.o
"Creature::setHP(int)", referenced from:
Player::Player() in Player.o
Player::Player() in Player.o
vtable for Player in Player.o
"Creature::attack(Creature*, Creature&, std::mersenne_twister_engine<unsigned int, 32ul, 624ul, 397ul, 31ul, 2567483615u, 11ul, 4294967295u, 7ul, 2636928640u, 15ul, 4022730752u, 18ul, 1812433253u>&, DungeonLevel&)", referenced from:
vtable for Player in Player.o
"Creature::getXLoc()", referenced from:
vtable for Player in Player.o