Forum de la communauté SFML

Aide => Général => Discussion démarrée par: DrPapino le Novembre 22, 2020, 09:30:51 am

Titre: Compilation statique
Posté par: DrPapino le Novembre 22, 2020, 09:30:51 am
Bonjour :)

Je sèche complètement pour faire une compilation statique du fameux cercle vert..
L'objectif est de pouvoir exporter mon .exe à n'importe quel pour qu'il puisse l'exécuter même sans SFML d'installée.

Mon setup :
- Sublime Text 3
- GCC version 6.3.0
- MinGW DW32
- Version de SFML : toutes testées mais pour l'exemple partons sur la 2.5.1 / GCC 7.3.0 MinGW (DW2) - 32-bit

mon makefile :

# The location where SFML is installed
SFML_DIR=C:/SFML

# Location where SFML libraries are located
LIBDIR=$(SFML_DIR)/lib

# Arguments to pass to the compiler
CFLAGS=-I$(SFML_DIR)/include

# Set the rule that links the executable as the default
# This is the default because it is *first* in the file,
# not because of it's name!
default: compile

# Compile the source file
compile: main.cpp
        g++ -c main.cpp $(CFLAGS) -o main.o

run: main.cpp
        set PATH=%PATH%;C:/SFML/bin; & g++ main.o -o main.exe -L$(LIBDIR) -lsfml-graphics -lsfml-window -lsfml-system -lsfml-network & main.exe


static: main.cpp
        set PATH=%PATH%;C:/SFML/bin; & g++ main.o -o main.exe -DSFML_STATIC $(CFLAGS) -L$(LIBDIR) -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lfreetype -lopengl32 -lwinmm -lgdi32
 

mon main.cpp :

#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{

    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}

la compilation "standard" et le run sont ok, mais la compilation statique me donne cette erreur :

main.o:main.cpp:(.text+0x7c): undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
main.o:main.cpp:(.text+0xa2): undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
main.o:main.cpp:(.text+0xde): undefined reference to `_imp___ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
main.o:main.cpp:(.text+0x115): undefined reference to `_imp___ZN2sf11CircleShapeC1Efj'
main.o:main.cpp:(.text+0x126): undefined reference to `_imp___ZN2sf5Color5GreenE'
main.o:main.cpp:(.text+0x130): undefined reference to `_imp___ZN2sf5Shape12setFillColorERKNS_5ColorE'
main.o:main.cpp:(.text+0x142): undefined reference to `_imp___ZNK2sf6Window6isOpenEv'
main.o:main.cpp:(.text+0x162): undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
main.o:main.cpp:(.text+0x182): undefined reference to `_imp___ZN2sf6Window5closeEv'
main.o:main.cpp:(.text+0x1af): undefined reference to `_imp___ZN2sf5ColorC1Ehhhh'
main.o:main.cpp:(.text+0x1ca): undefined reference to `_imp___ZN2sf12RenderTarget5clearERKNS_5ColorE'
main.o:main.cpp:(.text+0x1dd): undefined reference to `_imp___ZN2sf12RenderStates7DefaultE'
main.o:main.cpp:(.text+0x1f1): undefined reference to `_imp___ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'
main.o:main.cpp:(.text+0x203): undefined reference to `_imp___ZN2sf6Window7displayEv'
main.o:main.cpp:(.text+0x229): undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
main.o:main.cpp:(.text+0x273): undefined reference to `_imp___ZN2sf12RenderWindowD1Ev'
main.o:main.cpp:(.text$_ZN2sf11CircleShapeD1Ev[__ZN2sf11CircleShapeD1Ev]+0xa): undefined reference to `_imp___ZTVN2sf11CircleShapeE'
main.o:main.cpp:(.text$_ZN2sf11CircleShapeD1Ev[__ZN2sf11CircleShapeD1Ev]+0x17): undefined reference to `_imp___ZTVN2sf11CircleShapeE'
main.o:main.cpp:(.text$_ZN2sf11CircleShapeD1Ev[__ZN2sf11CircleShapeD1Ev]+0x2a): undefined reference to `_imp___ZN2sf5ShapeD2Ev'
collect2.exe: error: ld returned 1 exit status
Makefile:24: recipe for target 'static' failed
mingw32-make: *** [static] Error 1
[Finished in 0.7s with exit code 2]
[cmd: ['mingw32-make', 'static']]
[dir: C:\Users\JeanLouis\Documents\Root\SFMLTest]
[path: "C:\Program Files\Java\jdk1.8.0_231\bin;";C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Skype\Phone\;C:\WINDOWS\System32\OpenSSH\;C:\MinGW\bin;C:\Users\JeanLouis\AppData\Local\Microsoft\WindowsApps;]
Titre: Re: Compilation statique
Posté par: G. le Novembre 22, 2020, 10:53:55 am
- GCC version 6.3.0
- MinGW DW32
- Version de SFML 2.5.1 / GCC 7.3.0 MinGW (DW2) - 32-bit
Citation de: https://www.sfml-dev.org/download/sfml/2.5.1/index-fr.php
La version du compilateur doit correspondre à 100% !
Bon bah je pense que voilà quoi, version différente.
Du coup soit tu utilises le même compilateur que la version de SFML que tu télécharges, soit tu compiles toi-même SFML avec ton compilateur.
Titre: Re: Compilation statique
Posté par: Laurent le Novembre 22, 2020, 05:58:46 pm
Avant cela, le problème ici c'est qu'il manque un petit -LSFML_STATIC dans les flags de compilation.