0

我的 MacBook 上默认使用 GNU 4.7.1。当我在学校的服务器上运行我的程序时,我不断收到大量的段错误。我从学校服务器下载了程序的当前状态,以便可以使用 NetBeans 帮助进行调试。在让更新的 GNU 替换我的 MacBook 继续设置为默认值的古老 4.2 版本时,我遇到了很多问题。

OSX 编译器对我来说是全新的,我无法调整我的 makefile 来编译我学校服务器上的所有内容。

人们告诉我使用 gcc 或 g++ 而不是其他的,但其他人告诉我这应该没关系。据我了解,OSX 为 c/c++ 的较新版本的 GNU 使用不同的库,现在 Clang 是标准?我想坚持使用 GNU/GCC,因为那是我在我的 CS 课程中使用的。

目前看来,当我的 makefile 尝试链接“std::mt19937”时,它找不到链接它的标头。

我的问题是:如何让我的 makefile 编译以便使用 std::mt19937 和 c++11 库?

生成文件

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++0x”换成 -std=c++11 和 -std=gnu++11。我也尝试将它们都添加。我也尝试用 g++ 交换 gcc,但我似乎尝试或更改的所有内容都会导致更多错误和警告。

这是当前错误消息的第一部分(它一直在继续):

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
4

1 回答 1

0

原来我把编译器的路径弄乱了,MacPorts 安装到了错误的位置?新的 OSX 安装和适当的 GNU undate 解决了它。

于 2013-04-30T21:19:57.427 回答