SFML community forums

Help => General => Topic started by: Sander777 on July 11, 2019, 01:12:01 pm

Title: SFML static linking
Post by: Sander777 on July 11, 2019, 01:12:01 pm
I have such C++ code
#include <iostream>
#include "SFML/Window.hpp"


int main() {
        sf::Window window(sf::VideoMode(800, 600), "test");

And such Makefile
CC                              := g++
DEBUG_FLAGS     := -mwindows
RELEASE_FLAGS   := -s -O3 -w -mwindows

BIN             := bin
SRC             := src
INCLUDE := -Iinclude
LIB             := -Llib

LIBRARIES := -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32

EXECUTABLE      := main.exe

all: $(SRC)/*

release: $(SRC)/*

        $(RM) $(BIN)/$(EXECUTABLE)


But I can't compile and I am geting such error
g++ -mwindows -Iinclude -Llib -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32 src/main.cpp -o bin/main.exe
d:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\CyberOni\AppData\Local\Temp\ccLj2xOO.o:main.cpp:(.text+0x7c): undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
d:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\CyberOni\AppData\Local\Temp\ccLj2xOO.o:main.cpp:(.text+0xa2): undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
d:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\CyberOni\AppData\Local\Temp\ccLj2xOO.o:main.cpp:(.text+0xdb): undefined reference to `_imp___ZN2sf6WindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
d:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\CyberOni\AppData\Local\Temp\ccLj2xOO.o:main.cpp:(.text+0xfe): undefined reference to `_imp___ZN2sf6WindowD1Ev'
collect2.exe: error: ld returned 1 exit status
Makefile:15: recipe for target 'all' failed
make: *** [all] Error 1
Title: Re: SFML static linking
Post by: Hapax on July 11, 2019, 10:29:31 pm
If I'm not mistaken - which I very well may be - SFML_STATIC should be declared before including SFML modules.

It's normal, as far as I'm aware, to define SFML_STATIC outside of the code and in some building properties; this allows dynamic builds with no change to the code - only those properties.
Title: Re: SFML static linking
Post by: Sander777 on July 12, 2019, 05:50:15 pm
Still error, but this time seems it looks different.


#include <iostream>
#include "SFML/Window.hpp"

int main() {
    sf::Window window(sf::VideoMode(800, 600), "test");

d:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\CyberOni\AppData\Local\Temp\ccAI5dco.o:main.cpp:(.text+0x7c): undefined reference to `sf::String::String(char const*, std::locale const&)'
d:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\CyberOni\AppData\Local\Temp\ccAI5dco.o:main.cpp:(.text+0xa0): undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
d:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\CyberOni\AppData\Local\Temp\ccAI5dco.o:main.cpp:(.text+0xd7): undefined reference to `sf::Window::Window(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
d:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users\CyberOni\AppData\Local\Temp\ccAI5dco.o:main.cpp:(.text+0xf8): undefined reference to `sf::Window::~Window()'
If I'm adding -DSFML_STATIC to compiler flags it gives me the same error message.
Title: Re: SFML static linking
Post by: eXpl0it3r on July 12, 2019, 06:26:18 pm
The $^ needs to be before the libraries, otherwise the source file won't know about the libraries.
Always follow the rule of thumb: If X depends on Y, X has to come before Y.