HomeЛюди и блогиRelated VideosMore From: GanonCode

How to Static Link An SFML2 Project on Windows Using MinGW GCC

74 ratings | 3340 views
Ever wanted to compile a program that doesn't depend on external DLLs at the cost of a larger executable file size? Static linking is the way, and you've come to the right place to learn how! In this video, you'll use CMake to generate the SFML build files, build the SFML files using GCC, and write a makefile and test program to compile a static linked SFML project. The two files used to make this tutorial can be downloaded here: https://github.com/GanonCode/SFMLWinGCCStatic
Html code for embedding videos on your blog
Text Comments (41)
Ipotrick (24 days ago)
I get this error: C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsfml-graphics-s C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsfml-window-s C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lsfml-system-s C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lfreetype C:/MinGW/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -ljpeg collect2.exe: error: ld returned 1 exit status mingw32-make: *** [Makefile:2: all] Error 1 what should I do?
Ipotrick (24 days ago)
GanonCode  Nice, for some reason I wrote the wrong path, it works now thank you very much!
GanonCode (24 days ago)
Make sure the directory you specify after the -L argument includes the library files it says it cannot find
hardik prajapati (4 months ago)
Thank You ! been trying to make this work for 4 hours. Phew...
ארד ארבל (4 months ago)
3:54 you type "mingw32-make install"... but I am using visual studio 2017... I choose it in the config so its ok, but what should i type instead of the mingw32-make?
GanonCode (24 days ago)
Joshua Lambert (5 months ago)
I've followed your tutorial closely but I've run into a snag. ccEM5rkM.o:test.cpp:(.text+0x7c): undefined reference to `sf::String::String(char const*, std::locale const&)' I've got a ton of similar errors. Can you lead me in the right direction for the fix?
Joshua Lambert (5 months ago)
Thanks for the quick reply. I sincerely appreciate that. So, as it turns out, I had to put everything on a single line in the make file. Using the backslash line continuation character I'm able things going with multiple lines. all: g++ test.cpp -o test.exe \ -D SFML_STATIC \ -I C:\Programming\SFML\include \ -L C:\Programming\SFML\lib \ -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lopengl32 \ -lwinmm -lgdi32 -lfreetype -ljpeg I'm using standard GnuWin32 Make. Though that shouldn't make much difference? I'm new to this (makefiles and linking) and it's been quite a learning experience. Your video was super helpful. Thanks again. -j
GanonCode (5 months ago)
Unfortunately the order in which you define your libraries is important. Including a library later than it is required in the code is generally what gets you errors like that. The solution is to include the necessary libraries in the proper order. See 6:00 in the video for the order used to create the example program. Note that if you include other libraries not in the video (like sfml-audio) then you may need to include additional libraries and ensure they are included in the proper order as well.
Vitaliy Moskalenko (5 months ago)
Many thanks. In books and on the Internet I have not found a solution to the problem, only here.
Adel-Hani Miloudi (8 months ago)
input point not found ?? pls help
GanonCode (8 months ago)
If it's looking for a dynamic link then you didn't do a static link. I'd recommend making sure you static link the program, as the tutorial shows.
Adel-Hani Miloudi (8 months ago)
i have an error, input point not found : _ZNKSt7__cxx1112basic_stringlcSt11char_traitslcESalcEE5findEcj is not found in the dynamic link D:\...\main.exe
GanonCode (8 months ago)
With no other information it sounds like you didn't include a main() function, but without being more specific I can't even begin to diagnose that problem.
TheStroyer (9 months ago)
Thanks alot!
Not Gate (10 months ago)
Perfect! Thanks a bunch.
Kaikalii (1 year ago)
This video was incredibly helpful.
GanonCode (1 year ago)
Good to hear, thanks!
Mark S (1 year ago)
Just the video I was looking for. Thanks man
GanonCode (1 year ago)
I'm glad it helped!
Shantykoff (1 year ago)
Gives me error when trying to mingw32 -make -install
Shantykoff (1 year ago)
GanonCode thanks, dude!
GanonCode (1 year ago)
Lol, no problem. mingw32-make is the name of the make program and install is the argument you pass to it, so there should only be that one space.
Shantykoff (1 year ago)
GanonCode I'm kinda blind XD
Shantykoff (1 year ago)
GanonCode right... Without space after mingw32
GanonCode (1 year ago)
I looked through the video again and I never type that. Are you talking about "mingw32-make install"?
Said Metiche (1 year ago)
you saved my life i was going crazy after trying to install all of this from the clion command promt
Michael Honey (1 year ago)
Great video. FYI MinGW will need to be installed prior. Even if it's included in Code::Blocks. Also, I think the enovripnment variables paths need to be set up for MinGW
Kahitar (1 year ago)
This was brilliant! Why only one video?
Kahitar (1 year ago)
That's nice, i'll subscribe then ;D
GanonCode (1 year ago)
I have more in the pipeline. I started working on a video while I was still at university, but then I realized I'd need to make some supplementary videos for the concepts that I don't really cover in that one. Then I had projects and papers due so I stopped working on them entirely. But it's summer now, and I should finally have the time to work on them!
In the final part you go too fast and the video is too short. Why do not you tell us how the library is compiled? Can you compile a library that includes all the libraries together? To make the program more compact? Thanks for the tutorial. As I am very crude, it is the second time I see it, and I fear it will not be the last. A greeting from Spain. Translated with Google.
GanonCode (1 year ago)
This video is intended to get you acquainted with the process for statically linking an SFML program with MinGW GCC. Explaining how compilation works is slightly more complicated and is a topic for a different video altogether. Glad to hear I could help a Spaniard :)
Maxim Tsai (1 year ago)
Clear, to the point, handles bug cases, and even subtitled. Wonderful tutorial!
GanonCode (1 year ago)
Thanks! The format was designed to address issues I have with other types of tutorials. I'm happy to hear that you appreciate it :)
子淇李 (1 year ago)
How can i link it on mac without xcode
GanonCode (1 year ago)
I only use Linux and Windows. My recommendation would be that you Google your question.
BlackHighwindDragoon (1 year ago)
That -DSFML_STATIC was a freaking headache. I was trying to compile directly in the CMD, i didn't knew what "-D" mean (define isn't it?), i am learning, thanks!.
GanonCode (1 year ago)
I can look into it. I have really, really basic experience with OpenGL programming but with a little research I should be able to figure out how to get freeGLUT up and running. In the meantime, https://open.gl/ is a site that I've used in the past that may or may not be of some service to you.
Johnny Mccrum (1 year ago)
I realize you might not check this channel, but any chance you could make a tutorial for how to statically link freeGLUT and OpenGL?
GanonCode (1 year ago)
It's a feature of GCC, whereby you supply a macro to the preprocessor. http://www.rapidtables.com/code/linux/gcc/gcc-d.htm But, I'm totally with you. Little details like that can be a pain if you don't already know what you're looking for.

Would you like to comment?

Join YouTube for a free account, or sign in if you are already a member.