如何让我的makefile编译/链接旧的和更新的GCC / GNU库? C ++

时间:2013-04-29 17:41:50

标签: c++ netbeans linker makefile gnu

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

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

人们告诉我使用gcc或g ++代替另一种,但是其他人告诉我它应该没关系。根据我的理解,OSX使用不同的库来为新版本的GNU for c / c ++,现在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 ++ 11和-std = gnu ++ 11换成“-std = c ++ 0x”。我也尝试过添加它们。我也尝试用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

1 个答案:

答案 0 :(得分:0)

原来我搞砸了我的编译器和安装到错误位置的MacPorts的路径?新的OSX安装和适当的GNU undated解决了它。