SFML static linking error
I tried to make static linked bin.
Here is code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <SFML/Window.hpp>
int main() {
sf::Window window(sf::VideoMode(800, 600), "SFML window");
while (window.isOpen()) {
// Process events
sf::Event event;
while (window.pollEvent(event)) {
// Close window: exit
if (event.type == sf::Event::Closed)
window.close();
}
window.display();
}
return 0;
}
|
My make file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
CC := g++
C_FLAGS := -std=c++17 -w
BIN := bin
SRC := src
INCLUDE := include
LIB := lib
LIBRARIES := -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32
ifeq ($(OS),Windows_NT)
EXECUTABLE := main.exe
else
EXECUTABLE := main
endif
all: $(BIN)/$(EXECUTABLE)
clean:
$(RM) $(BIN)/$(EXECUTABLE)
run: all
./$(BIN)/$(EXECUTABLE)
$(BIN)/$(EXECUTABLE): $(SRC)/*
$(CC) $(C_FLAGS) -I$(INCLUDE) -L$(LIB) $(LIBRARIES) $^ -o $@ */
|
but I have such error output:
g++ -std=c++17 -w -Iinclude -Llib -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32 src/main.cpp -o bin/main.exe
C:\Users\admin\AppData\Local\Temp\ccoKzdyM.o:main.cpp:(.text+0x7c): undefined reference to `_imp___ZN2sf6StringC1EPKcRKSt6locale'
C:\Users\admin\AppData\Local\Temp\ccoKzdyM.o:main.cpp:(.text+0xa2): undefined reference to `_imp___ZN2sf9VideoModeC1Ejjj'
C:\Users\admin\AppData\Local\Temp\ccoKzdyM.o:main.cpp:(.text+0xdb): undefined reference to `_imp___ZN2sf6WindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
C:\Users\admin\AppData\Local\Temp\ccoKzdyM.o:main.cpp:(.text+0xfe): undefined reference to `_imp___ZNK2sf6Window6isOpenEv'
C:\Users\admin\AppData\Local\Temp\ccoKzdyM.o:main.cpp:(.text+0x117): undefined reference to `_imp___ZN2sf6Window9pollEventERNS_5EventE'
C:\Users\admin\AppData\Local\Temp\ccoKzdyM.o:main.cpp:(.text+0x134): undefined reference to `_imp___ZN2sf6Window5closeEv'
C:\Users\admin\AppData\Local\Temp\ccoKzdyM.o:main.cpp:(.text+0x142): undefined reference to `_imp___ZN2sf6Window7displayEv'
C:\Users\admin\AppData\Local\Temp\ccoKzdyM.o:main.cpp:(.text+0x155): undefined reference to `_imp___ZN2sf6WindowD1Ev'
C:\Users\admin\AppData\Local\Temp\ccoKzdyM.o:main.cpp:(.text+0x18b): undefined reference to `_imp___ZN2sf6WindowD1Ev'
collect2.exe: error: ld returned 1 exit status
Makefile:26: recipe for target 'bin/main.exe' failed
make: *** [bin/main.exe] Error 1
|
src/main.cpp
should be before the libraries in the g++ command. Try moving $^
before $(LIBRARIES)
.
And I think you mean to use a capital W for the -W flag in C_FLAGS.
#define SFML_STATIC don't work
I Moved $^
before $(LIBRARIES
but have same errors
Try adding the -lsfml-graphics-s
.
If that doesn't work then try removing the -s
from the libraries and see if it works.
I removed -s
and it compiled but now it needs .dll but I need static linking (all in one exe without dll)
Does this compile line work?
g++ -std=c++17 -W -DSFML_STATIC main.cpp -lsfml-window-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32 |
dutch, don't work
acknowledged
Topic archived. No new replies allowed.