问题
Ok so I am trying to link SFML in a CodeLite project but with no success. So what have I done :
- Added the include folder of SFML to the IncludePaths of CodeLite.
- Added the lib folder of SFML to the LibrariesSearchPath of CodeLite.
Added SFML_STATIC to Preprocessors in CodeLite.
Added the libraries to the LinkerOptions like this :
sfml-graphics;sfml-window;sfml-audio;sfml-network;sfml-system
Added the 5 dll's(sfml-graphics-2.dll.. etc) to the debug folder and to the project folder
This is the build log :
C:\WINDOWS\system32\cmd.exe /C ""E:/Program Files (x86)/CodeBlocks/MinGW /bin/mingw32-make.exe" -j4 SHELL=cmd.exe -e -f Makefile""
"----------Building project:[ Test - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'F:/Dropbox/Programming/OpenGL/Test'
"E:/Program Files (x86)/CodeBlocks/MinGW/bin/g++.exe" -o ./Debug/Test @"Test.txt" -L. -LF:/Dropbox/Programming/SFML/SFML-2.3.2x86/lib sfml-graphics sfml-window sfml-audio sfml-network sfml-system
g++.exe: error: sfml-graphics: No such file or directory
g++.exe: error: sfml-window: No such file or directory
g++.exe: error: sfml-audio: No such file or directory
g++.exe: error: sfml-network: No such file or directory
g++.exe: error: sfml-system: No such file or directory
mingw32-make.exe[1]: *** [Debug/Test] Error 1
Test.mk:78: recipe for target 'Debug/Test' failed
mingw32-make.exe[1]: Leaving directory 'F:/Dropbox/Programming/OpenGL/Test'
mingw32-make.exe: *** [All] Error 2
Makefile:4: recipe for target 'All' failed
====1 errors, 0 warnings====
I am using CodeLite 9.0.9 and SFML-2.3.2x86.
回答1:
1. "Starting from SFML 2.2, when static linking, you will have to link all of SFML's dependencies to your project as well. This means that if you are linking sfml-window-s or sfml-window-s-d for example, you will also have to link opengl32, winmm and gdi32. Some of these dependency libraries might already be listed under "Inherited values", but adding them again yourself shouldn't cause any problems." Your linked libraries should have -s suffix if you're linking statically and you should link other libraries look at this.
2."When linking to multiple SFML libraries, make sure that you link them in the right order, it is very important for GCC. The rule is that libraries that depend on other libraries must be put first in the list. Every SFML library depends on sfml-system, and sfml-graphics also depends on sfml-window. So, the correct order for these three libraries would be: sfml-graphics, sfml-window, sfml-system -- as shown in the screen capture above." Set linking order to graphics-s/window-s/system-s/etc
3."It is important to link to the libraries that match the configuration: "sfml-xxx-d" for Debug, and "sfml-xxx" for Release. A bad mix may result in crashes." From your build log I can see that you're building your project as Debug with Release libraries(those without -d suffix), then you have to change linked libraries to sfml-graphics-s-d/etc
If advices above won't work then you set search paths wrong. Good luck
回答2:
Ok so I finally managed to fix it by changing the libraries like this : -lsfml-graphics-s;-lsfml-window-s;-lsfml-audio-s;-lsfml-network-s;-lsfml-system-s;-lopengl32;-lfreetype;-ljpeg;-lwinmm;-lgdi32;-lopenal32;-lws2_32
来源:https://stackoverflow.com/questions/35105931/linking-sfml-in-codelite