所以我跟着这个教程:http://verra.xyz/howto/sfml.html 并收到此错误:
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lsfml-graphics
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lsfml-window
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lsfml-system
collect2.exe: error: ld returned 1 exit status
然后我将命令更改为“g++ main.cpp -o hello -Libsfml-system -Libsfml-window -Libsfml-graphics”并收到此错误:
C:\Users\Amar\AppData\Local\Temp\ccQNWfqZ.o:main.cpp:(.text+0x7c): undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
C:\Users\Amar\AppData\Local\Temp\ccQNWfqZ.o:main.cpp:(.text+0xa2): undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
C:\Users\Amar\AppData\Local\Temp\ccQNWfqZ.o:main.cpp:(.text+0xde): undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
C:\Users\Amar\AppData\Local\Temp\ccQNWfqZ.o:main.cpp:(.text+0x104): undefined reference to `_imp___ZNK2sf10WindowBase6isOpenEv'
C:\Users\Amar\AppData\Local\Temp\ccQNWfqZ.o:main.cpp:(.text+0x124): undefined reference to `_imp___ZN2sf10WindowBase9pollEventERNS_5EventE'
C:\Users\Amar\AppData\Local\Temp\ccQNWfqZ.o:main.cpp:(.text+0x144): undefined reference to `_imp___ZN2sf6Window5closeEv'
C:\Users\Amar\AppData\Local\Temp\ccQNWfqZ.o:main.cpp:(.text+0x171): undefined reference to `_imp___ZN2sf5ColorC1Ehhhh'
C:\Users\Amar\AppData\Local\Temp\ccQNWfqZ.o:main.cpp:(.text+0x18c): undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'
C:\Users\Amar\AppData\Local\Temp\ccQNWfqZ.o:main.cpp:(.text+0x19e): undefined reference to `_imp___ZN2sf6Window7displayEv'
C:\Users\Amar\AppData\Local\Temp\ccQNWfqZ.o:main.cpp:(.text+0x1b7): undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
C:\Users\Amar\AppData\Local\Temp\ccQNWfqZ.o:main.cpp:(.text+0x1f0): undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
collect2.exe: error: ld returned 1 exit status
我已经在 stackoverflow (Having problems setting up SFML with MinGW) 上找到了类似的主题,但没有有用的解决方案。
答案 0 :(得分:0)
您的第一个错误是因为 g++
找不到您要求它查找的库。您的第二个错误是因为您实际上并未在库中进行链接。
问题在于 -L
用于添加编译器将在其中查找库的目录,但它并没有告诉它链接到任何实际库中。标志 -l
实际上告诉编译器拉入并链接一个库。
就您而言,g++
不会在 c:\mingw\bin
中搜索库。您可以通过多种不同的方式解决此问题。
如果您知道库 (DLL) 的位置,例如,如果它们位于名为 c:\sfml
的文件夹中,您可以使用 g++
告诉 -Lc:/sfml
查看那里,然后告诉它使用 -l
链接库。所以你会使用 g++ -Lc:/sfml -lsfml-graphics -lsfml-window -lsfml-system
。
您也可以简单地将它们放在您知道 g++
会查看的地方。在您的情况下,您可以将它们放在 c:\mingw\lib
(而不是 c:\mingw\bin
)中。
我推荐您将 -L
设置为库路径的方式,因为总是必须安装这样的 DLL 很麻烦。