Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Trying to compile an SFML test  (Read 834 times)

0 Members and 1 Guest are viewing this topic.

Niidhogg

  • Newbie
  • *
  • Posts: 4
    • View Profile
Trying to compile an SFML test
« 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:
Quote
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:
Quote
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
......................................

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10989
    • View Profile
    • development blog
    • Email
Re: Trying to compile an SFML test
« Reply #1 on: July 18, 2023, 11:06:05 pm »
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. 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Niidhogg

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Trying to compile an SFML test
« Reply #2 on: July 18, 2023, 11:26:58 pm »
No I was using wrong version of MinGW probably.
I made it work on CMake using the template you linked, thank you !

 

anything