我已经在使用SFML的游戏上工作了一段时间,并且在我的Linux和Mac机器上进行出色的开发一直非常出色。最近,我尝试在Windows上编译游戏,但遇到许多问题。
我正在使用g ++和一个makefile。
g++ -std=c++17 -g -O2 -Wall -Wno-reorder -LSFML-2.5.1/lib -ISFML-2.5.1/include -o dungy Animation.o Camera.o Dust.o DustParticle.o Entity.o Game.o main.o Player.o PlayerTrail.o Room.o Textures.o Tile.o -lsfml-graphics -lsfml-audio -lsfml-window -lsfml-system
当我运行make时,会得到很多这样的未定义引用(链接到下面的完整输出):
Animation.o: In function `Animation::Animation(sf::Sprite*, int, bool)':
C:\Users\foxhu\Documents\Programming\C++\dungy/Animation.cpp:9: undefined reference to `__imp__ZNK2sf6Sprite15getGlobalBoundsEv'
C:\Users\foxhu\Documents\Programming\C++\dungy/SFML-2.5.1/include/SFML/Graphics/RectangleShape.hpp:41: undefined reference to `__imp__ZN2sf5ShapeD2Ev'
[使用Visual Studio时会输出类似的错误[完全遵循SFML网站的教程],但是它主要由随机字符组成。
Here's a link to the full output including the g++ command
我使用的是最新的SFML版本,并且过去曾使用g ++来使用几乎完全相同的makefile编译游戏,因此我为为何无法正常工作而感到du愧,在之后找不到任何在线帮助我的东西数小时的时间来寻找并尝试解决此问题。使用g ++和相同的makefile,该游戏可以在Mac和Linux上完美运行。
最后一件事是SFML网站说确保编译器版本100%匹配,我下载了他们为MinGW 7.3.0(32位)提供的版本,并下载了正确的SFML版本来匹配该版本。 。
编辑:
[Here's完整的makefile,如果出于某些原因需要它]
显然,我不得不使用调试库,而不必在any其他平台上使用。
我现在使用的makefile具有以下标志:
LDFLAGS = -lsfml-graphics-d -lsfml-audio-d -lsfml-window-d -lsfml-system-d
之前,我有这些LDFLAGS
,最后没有-d
。
不确定在Windows上为什么与Mac或Linux有所不同,但这继续使我不屑在编程时使用Windows。