Tell require where to find C libraries ?

86 views
Skip to first unread message

krs...@gmail.com

unread,
May 6, 2021, 6:54:47 AM5/6/21
to Racket Users

Hi!,

I am doing: (require taglib) and I get:
> (require taglib)
; ffi-lib: could not load foreign library
;   path: libtag_c.so.0
;   system error: File not found
; [,bt for context]

I am on OpenBSD and that file is at:
/usr/local/lib/libtag_c.so.3.0

How can I change my search path for C libs to be /usr/local ?

John Clements

unread,
May 6, 2021, 7:21:10 PM5/6/21
to krs...@gmail.com, Racket Users
It looks to me like you probably need to edit your “config.rktd” file:

https://docs.racket-lang.org/raco/config-file.html?q=config.rktd#%28idx._%28gentag._67._%28lib._scribblings%2Fraco%2Fraco..scrbl%29%29%29

On my machine (macOS using macports), for instance I have do do this for every new installation of drracket:

- edit <config-dir>/config.rktd to contain
(lib-search-dirs . (#f "/opt/local/lib”))

Let me know if I misunderstood your situation!

John Clements
> --
> You received this message because you are subscribed to the Google Groups "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to racket-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/b8425f0a-6d45-4954-9e32-df51aa5151cbn%40googlegroups.com.

krs...@gmail.com

unread,
May 6, 2021, 11:41:03 PM5/6/21
to Racket Users
Thanks for the help!
I was sure that was going to be it but it's not :(

This is what is on my system:
/usr/local/lib/libtag_c.so.3.0

racket is looking for libtag_c.so.0

So i'm not sure what to do next.

krs...@gmail.com

unread,
May 7, 2021, 8:08:26 AM5/7/21
to Racket Users
I'm so close :)

I installed taglib locally to /home/wise/root/lib, so I *have* the file exactly as racket is complaining about:
/home/wise/root/lib/libtag_c.so.0

I used your config example to edit (as root) /etc/racket/config.rktd
I added the "lib-search-dirs" line, so it looks like:
;; generated by unixstyle-install
#hash(
      (doc-dir . "/usr/local/share/doc/racket")
      (lib-dir . "/usr/local/lib/racket")
      (share-dir . "/usr/local/share/racket")
      (include-dir . "/usr/local/include/racket")
      (bin-dir . "/usr/local/bin")
      (apps-dir . "/usr/local/share/applications")
      (man-dir . "/usr/local/man")
      (absolute-installation? . #t)
      (build-stamp . "")
      (doc-search-url . "https://download.racket-lang.org/releases/7.9/doc/local-redirect/index.html")
      (catalogs . ("https://download.racket-lang.org/releases/7.9/catalog/"))
      (lib-search-dirs . (#f "/home/wise/root/lib"))
)

I still get the error:
Welcome to Racket v7.9 [cs].

> (require taglib)
; ffi-lib: could not load foreign library
;   path: libtag_c.so.0
;   system error: File not found
; [,bt for context]

I'm still poking at it, thanks again for the help.

krs...@gmail.com

unread,
May 7, 2021, 9:12:29 AM5/7/21
to Racket Users
I know it sees my custom dir, I ran this in racket:
> (require setup/dirs)
> (get-lib-search-dirs)
'(#<path:/home/wise/.local/share/racket/7.9/lib>
  #<path:/usr/local/lib/racket>
  #<path:/home/wise/root/lib>)

Nathaniel W Griswold

unread,
May 7, 2021, 9:53:44 AM5/7/21
to krs...@gmail.com, Racket Users
Folks,

One other thing you can do that might work here is to set an environment variable for yourself. I don’t remember the exact details of how libraries are looked up but on my system (mac os) i can do something like:


% ls /opt/local/lib/libtag_c.*
/opt/local/lib/libtag_c.0.0.0.dylib /opt/local/lib/libtag_c.0.dylib /opt/local/lib/libtag_c.dylib

% export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib
% racket
Welcome to Racket v7.9 [cs].
> (require taglib)

(success)

On BSD or linux i guess you can check `man ldconfig` and set something like LD_LIBRARY_PATH, or maybe there’s something a little closer to mac os x’s DYLD_FALLBACK_LIBRARY_PATH which i think works a little better (see https://stackoverflow.com/questions/3146274/is-it-ok-to-use-dyld-library-path-on-mac-os-x-and-whats-the-dynamic-library-s/3172515#3172515 )

Did you already try `export LD_LIBRARY_PATH=“$LD_LIBRARY_PATH:/usr/local/lib/"` ?

As for what John Clements said, I think in the past i have also set up the config.rktd in the exact same way, but i do not remember the details of the difference between the two methods. It seems to me that the environment variable method might be a little more flexible for chained loads, as it seems that if a c program were to load a dynamic library programmatically it simply would not know what your racket settings were. I guess another benefit is you don’t have to edit the system config.rktd, which doesn’t really seem like it’s meant to be changed unless you are specifying an entirely new PLTCONFIGDIR (or —config, or -G).

Maybe others can better elucidate pros/cons of
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/713e783e-db5f-4a19-8e4c-d33a6c842b57n%40googlegroups.com.

Nathaniel W Griswold

unread,
May 7, 2021, 10:02:20 AM5/7/21
to krs...@gmail.com, Racket Users
Also, i think in the past there were security limits in Mac OS X that prevented adjusting the dynamic library load path. I think maybe that's why i didn’t use them but things seem to be working through the env vars without any user changes to the default system security settings on my system, which is Big Sur 11.3.1.

Nate
> To view this discussion on the web visit https://groups.google.com/d/msgid/racket-users/79FA464A-DF94-412B-A11B-2FF70CC150DA%40manicmind.earth.

Ryan Culpepper

unread,
May 7, 2021, 10:29:21 AM5/7/21
to krs...@gmail.com, Racket Users
It looks like there are two issues. One is the shared library's directory, but the other is that the Racket library is looking for "libtag_c.so.0", and you have "libtag_c.so.3.0". That is, it's looking for a version suffix of "0", not "3.0" (see https://github.com/takikawa/taglib-racket/blob/master/taglib/taglib.rkt#L83).

One fix would be to change the Racket code to try "3.0" also. Maybe conditioned on the OS, since on Ubuntu I also get the library with suffix "0".

An alternative would be to copy or link /usr/local/lib/libtag_c.so.3.0 to Racket's lib directory with the file name the Racket code is trying to load:

  ln -s /usr/local/lib/libtag_c.so.3.0 ~/.local/share/racket/7.9/lib/libtag_c.so.0

Note: that assumes that the library versions are actually compatible; otherwise, the Racket code is likely to misbehave, even if it loads the library. Loading the shared library might still fail if the shared library itself has dependencies that are not in the default OS search path. (In that case, Nate's point about LD_LIBRARY_PATH might help.)

Ryan


krs...@gmail.com

unread,
May 7, 2021, 11:03:15 AM5/7/21
to Racket Users
Thanks for your help all!
I think you didn't see my last 2 replies.

I compiled taglib locally and set the library include path as seen in the racket REPL output.
I shouldn't need to do the symlink because my version is now the exact same file name as the REPL says cant be found.
(I it anyway, and it says same error file doesnt exist)

Also I ran:
(get-lib-search-dirs)
'(#<path:/home/wise/.local/share/racket/7.9/lib>
  #<path:/usr/local/lib/racket>
  #<path:/home/wise/root/lib>)  <-- LOOK AT THE DIR

The actaul file name that it says it cannot find is in that directory.
wise@dug:/home/wise$ ls -1 /home/wise/root/lib/                       <-- THIS IS IN MY "lib-search-dirs"                                                                                       
libtag.a
libtag.so.1
libtag.so.1.18.0
libtag_c.a
libtag_c.so.0   <-- THIS IS THE FILE IT SAYS CANNOT BE FOUND
libtag_c.so.0.0.0
pkgconfig


> (require taglib)
; ffi-lib: could not load foreign library
;   path: libtag_c.so.0   <-- SAYS IT CANNOT FIND THIS FILE

;   system error: File not found

krs...@gmail.com

unread,
May 7, 2021, 11:10:49 AM5/7/21
to Racket Users
OK ok ok, I did what na...@manicmind.earth said:

wise@dug:/home/wise$ export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/wise/root/lib"
wise@dug:/home/wise$ racket                                                        

Welcome to Racket v7.9 [cs].
> (require taglib)
>


SUCCESS :)

(I think something in the lib-search-dirs stuff isn't doing what it's supposed to, maybe if I get motivated i'll investigate more.)

Thanks again!

Ryan Culpepper

unread,
May 7, 2021, 11:33:17 AM5/7/21
to krs...@gmail.com, Racket Users
Sorry, I did miss those emails.

What do you see if you try (require taglib) after starting Racket with logging for "ffi-lib"? For example:

  $ PLTSTDERR="debug@ffi-lib" racket
  .... unrelated logging ....
  > (require taglib)
  ???

If it lists the file you pointed to in your email and says "(exists)", then the problem is probably that loading fails because libtag_c.so.0 depends on another shared library, and the dependency couldn't be found. On Linux, I would inspect shared library dependencies with the ldd command, but I don't know what to use on OpenBSD.

---

I see that setting LD_LIBRARY_PATH worked for you. The difference between Racket's search path (reported by get-lib-search-dirs) and the OS search path (which LD_LIBRARY_PATH extends) is that Racket's search path only applies to shared libraries loaded directly from Racket using ffi-lib; it doesn't apply to any other shared libraries that they depend on.

Ryan


krs...@gmail.com

unread,
May 7, 2021, 11:45:36 AM5/7/21
to Racket Users
This is fun :)
I unset the LD_LIBRARY_PATH and added the lib-search-dirs back to the config and ....

> (require taglib)
ffi-lib: failed for (ffi-lib "libtag_c" '("0")), tried:
  #<path:/home/wise/.local/share/racket/7.9/lib/libtag_c.so.0> (no such file)
  #<path:/home/wise/.local/share/racket/7.9/lib/libtag_c> (no such file)
  #<path:/usr/local/lib/racket/libtag_c.so.0> (no such file)
  #<path:/usr/local/lib/racket/libtag_c> (no such file)
  #<path:/home/wise/root/lib/libtag_c.so.0> (exists)
  #<path:/home/wise/root/lib/libtag_c> (no such file)
  "libtag_c.so.0" (using OS library search path)
  "libtag_c" (using OS library search path)
  #<path:/home/wise/data/RACKET/mytag/libtag_c.so.0> (no such file)
  #<path:/home/wise/data/RACKET/mytag/libtag_c> (no such file)

; ffi-lib: could not load foreign library
;   path: libtag_c.so.0
;   system error: File not found
; [,bt for context]
>


Look at that "exists" ...


Reply all
Reply to author
Forward
0 new messages