SFML community forums
Help => General => Topic started by: Niidhogg on July 18, 2023, 08:36:03 pm
-
Hey,
I trying out SFML, but I got a problem at compilation, probably at linking.
I tried the example that's here: https://www.sfml-dev.org/tutorials/2.6/start-linux.php
I'm on Windows 10 but i'm using make and mingw.
Here is my makefile:
cpp_flags := -Wall -W -std=c++20
sfml_path := C:\SFML-2.6.0
sfml_include := $(sfml_path)\include
sfml_lib := $(sfml_path)\lib
sfml_modules := -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32
test.exe: bin/test.o
g++ bin/test.o -o test.exe -L$(sfml_lib) $(sfml_modules) $(cpp_flags)
bin/test.o: src/test.cpp
g++ -c src/test.cpp -o bin/test.o -DSFML_STATIC -I$(sfml_include)
These are some of the errors I get:
ld.lld: error: undefined symbol: sf::String::String(char const*, std::__1::locale const&)
>>> referenced by bin/test.o:(main)
ld.lld: error: undefined symbol: std::basic_ostream<char, std::char_traits<char>>& std::__ostream_insert<char, std::char_traits<char>>(std::basic_ostream<char, std::char_traits<char>>&, char const*, long long)
>>> referenced by libsfml-graphics-s.a(RenderTarget.cpp.obj):((anonymous namespace)::RenderTargetImpl::factorToGlConstant(sf::BlendMode::Factor))
>>> referenced by libsfml-graphics-s.a(RenderTarget.cpp.obj):((anonymous namespace)::RenderTargetImpl::equationToGlConstant(sf::BlendMode::Equation))
>>> referenced by libsfml-graphics-s.a(RenderTarget.cpp.obj):((anonymous namespace)::RenderTargetImpl::equationToGlConstant(sf::BlendMode::Equation))
>>> referenced 227 more times
ld.lld: error: undefined symbol: std::ostream::put(char)
>>> referenced by libsfml-graphics-s.a(RenderTarget.cpp.obj):((anonymous namespace)::RenderTargetImpl::factorToGlConstant(sf::BlendMode::Factor))
>>> referenced by libsfml-graphics-s.a(RenderTarget.cpp.obj):((anonymous namespace)::RenderTargetImpl::equationToGlConstant(sf::BlendMode::Equation))
>>> referenced by libsfml-graphics-s.a(RenderTarget.cpp.obj):((anonymous namespace)::RenderTargetImpl::equationToGlConstant(sf::BlendMode::Equation))
>>> referenced 123 more times
ld.lld: error: undefined symbol: std::ostream::flush()
>>> referenced by libsfml-graphics-s.a(RenderTarget.cpp.obj):((anonymous namespace)::RenderTargetImpl::factorToGlConstant(sf::BlendMode::Factor))
>>> referenced by libsfml-graphics-s.a(RenderTarget.cpp.obj):((anonymous namespace)::RenderTargetImpl::equationToGlConstant(sf::BlendMode::Equation))
>>> referenced by libsfml-graphics-s.a(RenderTarget.cpp.obj):((anonymous namespace)::RenderTargetImpl::equationToGlConstant(sf::BlendMode::Equation))
>>> referenced 122 more times
......................................
-
Are you using the exact same MinGW version that SFML was built? Meaning the one linked on the download page and/or did you build SFML yourself?
While the errors aren't showing it yet, you're missing freetype as library to be linked.
When you link SFML statically, you have to link all of SFML's dependencies as well.
Personally, I highly recommend using CMake, good starting point is the SFML CMake Template (https://github.com/SFML/cmake-sfml-project). It builds SFML directly and configures everything, so you don't have to figure out these settings, plus it will automatically work on other platforms as well.
-
No I was using wrong version of MinGW probably.
I made it work on CMake using the template you linked, thank you !