【发布时间】:2014-01-05 14:53:39
【问题描述】:
我正在尝试让 SFML 2.1 与 MingW 一起使用,但这会导致问题。
我在 MingW 编译器中的编译行是:
g++ -ID:\SFML-2.1\include -LD:\SFML-2.1\lib main.cpp -lsfml-graphics -lsfml-window -lsfml-system
我正在尝试链接 .a 文件(这是否意味着我应该在编译行中添加一些东西?)。
代码如下:
#include <SFML/Graphics.hpp>
int main()
{
// create the window
sf::RenderWindow window(sf::VideoMode(800, 600), "My window");
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
// clear the window with black color
window.clear(sf::Color::White);
// draw everything here...
// window.draw(...);
// end the current frame
window.display();
}
return 0;
}
当我尝试编译时,我得到了这些错误:
$ make main
g++ -ID:\SFML-2.1\include -LD:\SFML-2.1\lib main.cpp -lsfml-graphics -lsfml-wind
ow -lsfml-system
C:\Users\Junker\AppData\Local\Temp\ccapaUOM.o:main.cpp:(.text+0xe5): undefined r
eference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
C:\Users\Junker\AppData\Local\Temp\ccapaUOM.o:main.cpp:(.text+0x10b): undefined
reference to `_imp___ZN2sf9VideoModeC1Ejjj'
C:\Users\Junker\AppData\Local\Temp\ccapaUOM.o:main.cpp:(.text+0x147): undefined
reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15Co
ntextSettingsE'
C:\Users\Junker\AppData\Local\Temp\ccapaUOM.o:main.cpp:(.text+0x178): undefined
reference to `_imp___ZN2sf6Window5closeEv'
C:\Users\Junker\AppData\Local\Temp\ccapaUOM.o:main.cpp:(.text+0x18d): undefined
reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
C:\Users\Junker\AppData\Local\Temp\ccapaUOM.o:main.cpp:(.text+0x1a4): undefined
reference to `_imp___ZN2sf5Color5WhiteE'
C:\Users\Junker\AppData\Local\Temp\ccapaUOM.o:main.cpp:(.text+0x1ae): undefined
reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'
C:\Users\Junker\AppData\Local\Temp\ccapaUOM.o:main.cpp:(.text+0x1c0): undefined
reference to `_imp___ZN2sf6Window7displayEv'
C:\Users\Junker\AppData\Local\Temp\ccapaUOM.o:main.cpp:(.text+0x1cf): undefined
reference to `_imp___ZNK2sf6Window6isOpenEv'
C:\Users\Junker\AppData\Local\Temp\ccapaUOM.o:main.cpp:(.text+0x1e7): undefined
reference to `_imp___ZN2sf12RenderWindowD1Ev'
C:\Users\Junker\AppData\Local\Temp\ccapaUOM.o:main.cpp:(.text+0x20e): undefined
reference to `_imp___ZN2sf12RenderWindowD1Ev'
C:\Users\Junker\AppData\Local\Temp\ccapaUOM.o:main.cpp:(.text+0x235): undefined
reference to `_imp___ZN2sf12RenderWindowD1Ev'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\J
unker\AppData\Local\Temp\ccapaUOM.o: bad reloc address 0xf in section `.text$_ZN
2sf6StringD1Ev[__ZN2sf6StringD1Ev]'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link
failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
make: *** [main] Error 1
我做错了什么?错误说未定义的引用,这意味着找不到某些东西(库?)。
SFML 2.1 包附带了调试库和发布库 (libsfml--s-d),这与它有关吗?
【问题讨论】:
-
奇怪;你的调用在我看来是正确的。尝试使用
-DSFML_STATIC的静态库。 -
我尝试下载不同版本的 SFML 2.1,现在它可以编译(耶!:D),但程序无法运行,我收到错误:0xc000007b。该库是 32 位的,但我的操作系统是 64 位的。这有关系吗?
-
不应该; x86-64 与 x86 兼容(或者您的许多程序无法运行)不过,您可能应该确保 您的 代码也被编译为 32 位。
-
该错误意味着它找不到某些共享库(Windows 下的
.dll)。见stackoverflow.com/questions/10492037/… -
调试/发布可能与动态与静态运行时有关。在 Windows 上,调试和发布运行时相互不兼容,您必须在 编译 时进行选择。您还必须选择是在编译时链接静态库还是共享库(需要特殊定义)。不幸的是,我不记得 MinGW 上的特定选项组合。
标签: c++ mingw undefined-reference