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

Author Topic: SFML static linking  (Read 192 times)

0 Members and 1 Guest are viewing this topic.

Sander777

  • Newbie
  • *
  • Posts: 2
    • View Profile
SFML static linking
« on: July 11, 2019, 01:12:01 pm »
I have such C++ code
#include <iostream>
#include "SFML/Window.hpp"

#define SFML_STATIC

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)/*
        $(CC) $(DEBUG_FLAGS) $(INCLUDE) $(LIB) $(LIBRARIES) $^ -o $(BIN)/$(EXECUTABLE)

release: $(SRC)/*
        $(CC) $(RELEASE_FLAGS) $(INCLUDE) $(LIB) $(LIBRARIES) $^ -o $(BIN)/$(EXECUTABLE)

clean:
        $(RM) $(BIN)/$(EXECUTABLE)

run:
        ./$(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
 
« Last Edit: July 11, 2019, 01:33:39 pm by Sander777 »

Hapax

  • Hero Member
  • *****
  • Posts: 2791
  • My number of posts is shown in hexadecimal.
    • View Profile
Re: SFML static linking
« Reply #1 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.
Selba Ward - SFML drawables
Kairos - Timing Library
Rectangular Boundary Collision - Rectangular SAT Collision

@Hapaxiation - Hapaxia on Twitter

Sander777

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: SFML static linking
« Reply #2 on: July 12, 2019, 05:50:15 pm »
Still error, but this time seems it looks different.

#define SFML_STATIC

#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.
« Last Edit: July 12, 2019, 05:53:19 pm by Sander777 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 9355
    • View Profile
    • development blog
    • Email
Re: SFML static linking
« Reply #3 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Nightly Builds: https://www.nightlybuilds.ch/
——————————————————————
Dev Blog: https://dev.my-gate.net/
Thor: http://www.bromeon.ch/libraries/thor/