简体   繁体   English

如何获取我的makefile来编译/链接旧的和较新的GCC / GNU库? C ++

[英]How can I get my makefile to compile/link older and newer GCC/GNU libraries? C++

I have GNU 4.7.1 as the default on my MacBook. 我在MacBook上将GNU 4.7.1作为默认设置。 I keep getting tons of segfaults when I run my program on my school's server. 在学校的服务器上运行程序时,我不断收到大量的段错误。 I downloaded the current state of my program from my schools server so that I could use NetBeans to help with debugging. 我从学校服务器下载了程序的当前状态,以便可以使用NetBeans进行调试。 I've run into tons of problems getting the newer GNU to replace the ancient 4.2 version that my MacBook was continuing to set as the default. 我遇到了很多问题,无法使用更新的GNU替换MacBook继续设置为默认值的古老4.2版本。

The OSX compilers are completely new to me and I can't get my makefile adjusted to compile everything like it is on my school's server. OSX编译器对我来说是全新的,我无法调整我的makefile来编译学校服务器上的所有文件。

People have told me to use gcc or g++ instead of the other, but others have told me that it shouldn't matter. 人们告诉我使用gcc或g ++代替其他方法,但是其他人告诉我这没关系。 From what I understand, OSX uses different libraries for the newer versions of GNU for c/c++ and now Clang is the standard? 据我了解,OSX对c / c ++的较新版本的GNU使用不同的库,现在Clang是标准的吗? I'd like to stick with GNU/GCC just because that's what I've used in my CS classes. 我只想坚持使用GNU / GCC,因为那是我在CS类中使用的。

Currently it appears that when my makefile tries to link "std::mt19937" it can't find the header that links it. 当前看来,当我的makefile尝试链接“ std :: mt19937”时,找不到链接它的头。

My question is : how can I get my makefile to compile so that std::mt19937 and the c++11 libraries both are used? 我的问题是 :如何获取我的makefile进行编译,以便同时使用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

I tried swapping out "-std=c++0x" for -std=c++11 and -std=gnu++11. 我尝试将“ -std = c ++ 0x”换成-std = c ++ 11和-std = gnu ++ 11。 I also tried adding them both. 我还尝试将它们都添加。 I also tried swapping gcc out with g++ but everything I seem to try or change causes more errors and warnings. 我也尝试过用g ++换出gcc,但我尝试或更改的所有内容都会导致更多错误和警告。

Here's the first part of the current error message (It goes on and on and on): 这是当前错误消息的第一部分(持续不断):

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

Turns out I messed up the path for my compiler and MacPorts installed to the wrong location? 原来我弄乱了将编译器和MacPorts安装到错误位置的路径? Fresh OSX install and proper GNU undated solves it. 重新安装OSX并使用适当的未更新GNU即可解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM