1

I am trying to compile a program that requires SFML 2.41+. Ubuntu 16.04's repos don't have a new enough version so I installed SFML 2.4.2 by following the (somewhat sparse) instructions on this page. Specifically I dowloaded the Linux version from this page, extracted it, dug down until I found the lib, share, and include folders and copied those folders over the folders of the same name in /usr/local/.

When running the included Makefile I get the following errors:

/usr/bin/ld: cannot find -lsfml-system
/usr/bin/ld: cannot find -lsfml-window
/usr/bin/ld: cannot find -lsfml-graphics

Focusing on sfml-system for the moment, if I run ld -lsfml-system --verbose | grep /usr/local/lib I get the following:

attempt to open //usr/local/lib/x86_64-linux-gnu/libsfml-system.so failed
attempt to open //usr/local/lib/x86_64-linux-gnu/libsfml-system.a failed
attempt to open //usr/local/lib/libsfml-system.so failed
attempt to open //usr/local/lib/libsfml-system.a failed

if I run sudo ls -l /usr/local/lib | grep libsfml-system.so I get the following:

lrwxrwxrwx  1 root   root        21 Oct 16 01:38 libsfml-system.so -> libsfml-system.so.2.4
lrwxrwxrwx  1 root   root        23 Oct 16 01:38 libsfml-system.so.2.4 -> libsfml-system.so.2.4.2
-rw-r--r--  1 root   root     72080 Feb 10  2017 libsfml-system.so.2.4.2

So I appear to have a symlink to a .so file in the path ld is looking in. Why can't it load the library?

(I was initially concerned about the double slashes, but this question suggests those are okay.)


what i've tried so far

I've now tried running sudo ldconfig and sudo ldconfig /usr/local/lib/. Neither of those have changed the behaviour of ld -lsfml-system

Specifcally when I run sudo ldconfig --verbose 2> /dev/null | grep sfml I get

    libsfml-window.so.2.4 -> libsfml-window.so.2.4.2
    libsfml-graphics.so.2.4 -> libsfml-graphics.so.2.4.2
    libsfml-audio-d.so.2.4 -> libsfml-audio-d.so.2.4.2
    libsfml-graphics-d.so.2.4 -> libsfml-graphics-d.so.2.4.2
    libsfml-audio.so.2.4 -> libsfml-audio.so.2.4.2
    libsfml-window-d.so.2.4 -> libsfml-window-d.so.2.4.2
    libsfml-system.so.2.4 -> libsfml-system.so.2.4.2
    libsfml-system-d.so.2.4 -> libsfml-system-d.so.2.4.2
    libsfml-network-d.so.2.4 -> libsfml-network-d.so.2.4.2
    libsfml-network.so.2.4 -> libsfml-network.so.2.4.2
    libsfml-network.so.2.3 -> libsfml-network.so.2.3.2
    libsfml-graphics.so.2.3 -> libsfml-graphics.so.2.3.2
    libsfml-system.so.2.3 -> libsfml-system.so.2.3.2
    libsfml-window.so.2.3 -> libsfml-window.so.2.3.2

(On stderr I just get messages that appear to be merely informational,for example:

/sbin/ldconfig.real: Path `/usr/local/lib' given more than once

and

/sbin/ldconfig.real: /lib/i386-linux-gnu/ld-2.23.so is the dynamic linker, ignoring

so I figured they weren't important.)


Since /etc/ld.so.cache was mentioned, I made a copy of it with cp /etc/ld.so.cache /etc/ld.so.cache.bak and re-ran sudo ldconfig. A new cache file was generated but it wasn't any different, that is diff /etc/ld.so.cache /etc/ld.so.cache.bak doesn't print anything.

Ryan1729
  • 940
  • 7
  • 25
  • You *did* add the option `-L/usr/local/lib` when linking? Most Linux systems doesn't have `/usr/local/lib` in the standard library search path. – Some programmer dude Oct 16 '17 at 08:54
  • The second block of output contains `attempt to open //usr/local/lib/libsfml-system.so failed` so for whatever reason my system seems to be searching there. – Ryan1729 Oct 16 '17 at 09:07
  • @Someprogrammerdude Just because nothing else was working I tried running `ld -L/usr/local/lib -lsfml-system --verbose` but I get the same results as above. – Ryan1729 Oct 17 '17 at 00:33
  • 1
    Try running `strace ld -lsfml-system --verbose` and see if there's anything pointing out why the "attempt to open" fails. – Michael Burr Oct 17 '17 at 04:10
  • @MichaelBurr I get `stat("//usr/local/lib/libsfml-system.so", 0x7ffc794d3fd0) = -1 EACCES (Permission denied)` in the output! If I try `sudo make` then the compilation seems to get further, (it stops on an undefined reference error). But other `.so` files in my `/usr/local/lib/` folder seem to have the same owner and permissions flags, (root and read and execute available for everyone.) I should be able to run `make` without `sudo` right? – Ryan1729 Oct 17 '17 at 04:49
  • 1
    All separate parts of the path `/usr/local/lib/libsfml-system.so` needs to be readable by all. If e.g. the `/usr/local/lib` directory is not readable by all then you will have such an error. Or the library file itself. I'm guessing that due to your "installation" method (just copying over the directories) you might have changed the default permissions. – Some programmer dude Oct 17 '17 at 05:28
  • That was it! Thanks for the help @Someprogrammerdude ! – Ryan1729 Oct 17 '17 at 05:53
  • And thanks for suggesting `strace` and @MichaelBurr ! – Ryan1729 Oct 17 '17 at 05:54

2 Answers2

2

The problem turned out to be that the permissions on my /usr/local/lib/ got changed when I copied the files over them. Specifically the execute bits seem to have been unset. After setting those again, I can now link those libraries properly!

Ryan1729
  • 940
  • 7
  • 25
0

The standard Linux libraries are cached in /etc/ld.so.cache. If you add libraries to the standard path, you need to also run (as root) ldconfig.

Shachar Shemesh
  • 8,193
  • 6
  • 25
  • 57