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

Author Topic: Problem with a make file  (Read 2820 times)

0 Members and 5 Guests are viewing this topic.

Armoured

  • Newbie
  • *
  • Posts: 3
    • View Profile
Problem with a make file
« on: October 07, 2017, 03:12:04 pm »
Hi,
I have made this make file to compile a little SFML test:

#OBJS specifies which files to compile as part of the project
OBJS = Test.cpp

#OBJ_NAME specifies the name of our exectuable
OBJ_NAME = Test

#CC specifies which compiler we're using
CC = g++

#INCLUDE_PATHS specifies the additional include paths we'll need
INCLUDE_PATHS = -ID:\Programming\dev_lib\SFML-2.4.2-Static\include

#LIBRARY_PATHS specifies the additional library paths we'll need
LIBRARY_PATHS = -LD:\Programming\dev_lib\SFML-2.4.2-Static\lib

#COMPILER_FLAGS specifies the additional compilation options we're using
# -w suppresses all warnings
# -Wl,-subsystem,windows gets rid of the console window
COMPILER_FLAGS = -m64 -O3 -w -Wl,-subsystem,windows

#LINKER_FLAGS specifies the libraries we're linking against
LINKER_FLAGS = -static-libgcc -static-libstdc++ -lmingw32 -lopengl32 -lwinmm -lgdi32 -lfreetype -ljpeg -lopenal32 -lFLAC -lvorbisenc -lvorbisfile -lvorbis -logg -lsfml-graphics-s -lsfml-window-s -lsfml-audio-s -lsfml-system-s

#This is the target that compiles our executable
all:    $(OBJS)
        $(CC) $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME)
 

I use the static version of SFML 2.4.2 but when i compile "Test.cpp" I have some link errors.
I have made errors in the "LINKER_FLAGS"?  :'(

Thanks

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10998
    • View Profile
    • development blog
    • Email
Re: Problem with a make file
« Reply #1 on: October 07, 2017, 03:33:02 pm »
The linker order matters. I tend to follow the "x depends on y" rule, so if x depends on y, x has to come before y.

For example sfml-audio depends on ogg, so they can't be listed before SFML.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Armoured

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Problem with a make file
« Reply #2 on: October 07, 2017, 04:12:00 pm »
The linker order matters. I tend to follow the "x depends on y" rule, so if x depends on y, x has to come before y.

For example sfml-audio depends on ogg, so they can't be listed before SFML.

Ok! I have changed the link options in this:
LINKER_FLAGS = -static-libgcc -static-libstdc++ -lmingw32 -lsfml-graphics-s -lsfml-window-s -lsfml-audio-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32 -lfreetype -ljpeg -lopenal32 -lFLAC -lvorbisenc -lvorbisfile -lvorbis -logg
 

But I have these link errors:
g++ Test.cpp -ID:\Programming\dev_lib\SFML-2.4.2-Static\include -LD:\Programming\dev_lib\SFML-2.4.2-Static\lib -m64 -O3 -w -Wl,-subsystem,windows -static-libgcc -static-libstdc++ -lmingw32 -lsfml-graphics-s -lsfml-window-s -lsfml-audio-s -lsfml-system-s -lopengl32 -lwinmm -lgdi32 -lfreetype -ljpeg -lopenal32 -lFLAC -lvorbisenc -lvorbisfile -lvorbis -logg -o Test
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text$_ZN2sf4TextD1Ev[_ZN2sf4TextD1Ev]+0x9): undefined reference to `__imp__ZTVN2sf4TextE'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text$_ZN2sf4TextD1Ev[_ZN2sf4TextD1Ev]+0x10): undefined reference to `__imp__ZTVN2sf11VertexArrayE'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text$_ZN2sf4TextD1Ev[_ZN2sf4TextD1Ev]+0x83): undefined reference to `__imp__ZN2sf13TransformableD2Ev'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x8b): undefined reference to `__imp__ZN2sf6StringC1EPKcRKSt6locale'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0xbb): undefined reference to `__imp__ZN2sf9VideoModeC1Ejjj'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0xff): undefined reference to `__imp__ZN2sf12RenderWindowC1ENS_9VideoModeERKNS_6StringEjRKNS_15ContextSettingsE'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x138): undefined reference to `__imp__ZN2sf7TextureC1Ev'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x167): undefined reference to `__imp__ZN2sf7Texture12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_4RectIiEE'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x193): undefined reference to `__imp__ZN2sf6SpriteC1ERKNS_7TextureE'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x1a1): undefined reference to `__imp__ZN2sf4FontC1Ev'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x1c4): undefined reference to `__imp__ZN2sf4Font12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x220): undefined reference to `__imp__ZN2sf4TextC1ERKNS_6StringERKNS_4FontEj'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x24d): undefined reference to `__imp__ZN2sf5MusicC1Ev'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x270): undefined reference to `__imp__ZN2sf5Music12openFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x29c): undefined reference to `__imp__ZN2sf11SoundStream4playEv'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x2a3): undefined reference to `__imp__ZN2sf6Window9pollEventERNS_5EventE'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x2aa): undefined reference to `__imp__ZN2sf12RenderStates7DefaultE'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x2b5): undefined reference to `__imp__ZNK2sf6Window6isOpenEv'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x2f2): undefined reference to `__imp__ZN2sf5ColorC1Ehhhh'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x2ff): undefined reference to `__imp__ZN2sf12RenderTarget5clearERKNS_5ColorE'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x310): undefined reference to `__imp__ZN2sf12RenderTarget4drawERKNS_8DrawableERKNS_12RenderStatesE'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x327): undefined reference to `__imp__ZN2sf6Window7displayEv'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x339): undefined reference to `__imp__ZN2sf4FontD1Ev'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x340): undefined reference to `__imp__ZTVN2sf6SpriteE'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x362): undefined reference to `__imp__ZN2sf13TransformableD2Ev'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x36d): undefined reference to `__imp__ZN2sf7TextureD1Ev'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x376): undefined reference to `__imp__ZN2sf12RenderWindowD1Ev'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x3a3): undefined reference to `__imp__ZN2sf5MusicD1Ev'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x3b6): undefined reference to `__imp__ZN2sf6Window5closeEv'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x3e6): undefined reference to `__imp__ZN2sf5MusicD1Ev'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x3f9): undefined reference to `__imp__ZN2sf4FontD1Ev'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x400): undefined reference to `__imp__ZTVN2sf6SpriteE'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x422): undefined reference to `__imp__ZN2sf13TransformableD2Ev'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x42d): undefined reference to `__imp__ZN2sf7TextureD1Ev'
C:\Users\Black-Beast\AppData\Local\Temp\ccPHooZo.o:Test.cpp:(.text.startup+0x436): undefined reference to `__imp__ZN2sf12RenderWindowD1Ev'
collect2.exe: error: ld returned 1 exit status
Makefile:26: recipe for target 'all' failed
mingw32-make: *** [all] Error 1
 

Please can you give to me an example of the right link order?
Thanks

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10998
    • View Profile
    • development blog
    • Email
Re: Problem with a make file
« Reply #3 on: October 07, 2017, 05:33:15 pm »
__imp__ means "import" which means it's trying to find dynamically (imported) linked library symbols, so since you're linking the static libs you also need to define SFML_STATIC (-DSFML_STATIC).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Armoured

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Problem with a make file
« Reply #4 on: October 07, 2017, 06:33:24 pm »
__imp__ means "import" which means it's trying to find dynamically (imported) linked library symbols, so since you're linking the static libs you also need to define SFML_STATIC (-DSFML_STATIC).

Perfect!
I changed the link options in this:
LINKER_FLAGS = -DSFML_STATIC -static-libgcc -static-libstdc++ -lmingw32 -lsfml-graphics-s -lsfml-window-s -lsfml-audio-s -lsfml-system-s -lopengl32 -lfreetype -ljpeg -lwinmm -lgdi32 -lopenal32 -lFLAC -lvorbisenc -lvorbisfile -lvorbis -logg
 

And now all works well  :)
Thanks again eXpl0it3r!

 

anything