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

Author Topic: Unresolved references when linking shared objects made with cmake  (Read 1718 times)

0 Members and 1 Guest are viewing this topic.

Demiu

  • Newbie
  • *
  • Posts: 4
    • View Profile
So I ran into a problem that SFML provided from my repository didn't load an OpenGL function that I needed (namely glAlphaFunc). However, it was added in SFML's later commit, so I pulled master from github and ran cmake (Debug, shared) and make. Then I copied files from /lib from that build and moved it into my own project's directory.
The problem is that when I link those .so files, not the ones in /usr/lib then I get an "undefined reference" error for every function that should be in there. How can I fix that?

My make command is:
Code: [Select]
g++ <My project's objects> -o <executable path> -lGL -lpthread -lX11 -lxcb -lX11-xcb -lxcb-randr -lxcb-image -ludev -lfreetype -ljpeg -lopenal -lFLAC -lvorbis -LSource/Extern/SFML/Archives/libsfml-system-d.so -LSource/Extern/SFML/Archives/libsfml-window-d.so -LSource/Extern/SFML/Archives/libsfml-graphics-d.so -LSource/Extern/SFML/Archives/libsfml-network-d.so -LSource/Extern/SFML/Archives/libsfml-audio-d.so

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Unresolved references when linking shared objects made with cmake
« Reply #1 on: February 09, 2016, 10:19:04 am »
The link order is wrong. Libraries that depend on other libraries need to be placed first.
Since SFML depends on GL, all the X-libs, etc. you need to place SFML before them all.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Demiu

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Unresolved references when linking shared objects made with cmake
« Reply #2 on: February 10, 2016, 12:34:01 am »
I changed the order to
-LSource/Extern/SFML/Archives/libsfml-graphics-d.so -LSource/Extern/SFML/Archives/libsfml-window-d.so -LSource/Extern/SFML/Archives/libsfml-network-d.so -LSource/Extern/SFML/Archives/libsfml-audio-d.so -LSource/Extern/SFML/Archives/libsfml-system-d.so -lGL -lpthread -lX11 -lxcb -lX11-xcb -lxcb-randr -lxcb-image -ludev -lfreetype -ljpeg -lopenal -lFLAC -lvorbis

And it still throws a lot of undef refs.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Unresolved references when linking shared objects made with cmake
« Reply #3 on: February 10, 2016, 01:55:25 am »
What kinds? Some other stuff might be out of order or missing.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: Unresolved references when linking shared objects made with cmake
« Reply #4 on: February 10, 2016, 09:55:01 am »
I changed the order to
-LSource/Extern/SFML/Archives/libsfml-graphics-d.so -LSource/Extern/SFML/Archives/libsfml-window-d.so -LSource/Extern/SFML/Archives/libsfml-network-d.so -LSource/Extern/SFML/Archives/libsfml-audio-d.so -LSource/Extern/SFML/Archives/libsfml-system-d.so -lGL -lpthread -lX11 -lxcb -lX11-xcb -lxcb-randr -lxcb-image -ludev -lfreetype -ljpeg -lopenal -lFLAC -lvorbis

And it still throws a lot of undef refs.

Usually, -L is for directory and -l for files. I don't know if you're compiler is more flexible than others, but you should use -LSource/Extern/SFML/Archives/ -lsfml-system -lsfml-window -lsfml-graphics -lsfml-audio -lsfml-network. Also, since you're using shared libraries, you needn't link to SFML's dependencies.
SFML / OS X developer

Demiu

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Unresolved references when linking shared objects made with cmake
« Reply #5 on: February 11, 2016, 01:12:38 pm »
Yup, changing to -L<.so dir> -lsfml-graphics-d -lsfml-window-d and so on plus moving all of SFML libraries at the start of linker's list worked, thank you for your help.

 

anything