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

Author Topic: Error when linking project on CSFML  (Read 9332 times)

0 Members and 1 Guest are viewing this topic.

DevilArx

  • Newbie
  • *
  • Posts: 2
    • View Profile
Error when linking project on CSFML
« on: April 14, 2017, 07:43:46 pm »
When i compile a project, I get this error:

OS: Windows 7

C:\Users\DevilArx\Workspace\Roguelike-study>gcc *.o -L"lib/CSFML/lib" -lcsfml-window-2 -lcsfml-graphics-2 -lcsfml-system-2
main.o:main.c:(.text+0x56): undefined reference to `_imp__sfRenderWindow_create'
main.o:main.c:(.text+0x8c): undefined reference to `_imp__sfRenderWindow_close'
main.o:main.c:(.text+0xa2): undefined reference to `_imp__sfRenderWindow_pollEvent'
main.o:main.c:(.text+0xad): undefined reference to `_imp__sfBlack'
main.o:main.c:(.text+0xbf): undefined reference to `_imp__sfRenderWindow_clear'
main.o:main.c:(.text+0xcd): undefined reference to `_imp__sfRenderWindow_display'
main.o:main.c:(.text+0xdb): undefined reference to `_imp__sfRenderWindow_isOpen'
main.o:main.c:(.text+0xed): undefined reference to `_imp__sfRenderWindow_destroy'
collect2.exe: error: ld returned 1 exit status

Tell me please how can I fix this?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Error when linking project on CSFML
« Reply #1 on: April 14, 2017, 07:50:09 pm »
Use the proper linking order. The graphics module depends on the window module so tje graphics module has to be linked before the window module.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

DevilArx

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Error when linking project on CSFML
« Reply #2 on: April 14, 2017, 08:07:26 pm »
After changing the order, the errors still remains

C:\Users\DevilArx\Workspace\Roguelike-study>gcc *.o -L"lib/CSFML/lib" -lcsfml-graphics-2 -lcsfml-window-2 -lcsfml-system-2
main.o:main.c:(.text+0x56): undefined reference to `_imp__sfRenderWindow_create'
main.o:main.c:(.text+0x8c): undefined reference to `_imp__sfRenderWindow_close'
main.o:main.c:(.text+0xa2): undefined reference to `_imp__sfRenderWindow_pollEvent'
main.o:main.c:(.text+0xad): undefined reference to `_imp__sfBlack'
main.o:main.c:(.text+0xbf): undefined reference to `_imp__sfRenderWindow_clear'
main.o:main.c:(.text+0xcd): undefined reference to `_imp__sfRenderWindow_display'
main.o:main.c:(.text+0xdb): undefined reference to `_imp__sfRenderWindow_isOpen'
main.o:main.c:(.text+0xed): undefined reference to `_imp__sfRenderWindow_destroy'
collect2.exe: error: ld returned 1 exit status

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Error when linking project on CSFML
« Reply #3 on: April 14, 2017, 10:24:46 pm »
Your main object files need to be placed before linking libraries.
Just remember to use the "depends on"-rule: main.o depends on sfml-graphics depends on sfml-window depends on sfml-system
That gives you the linking order.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/