unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Can't use dynamic-link with any shared object file
@ 2016-12-26 17:25 saffronsnail
  2016-12-26 22:24 ` Jan Wedekind
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: saffronsnail @ 2016-12-26 17:25 UTC (permalink / raw)
  To: guile-user

Hello, 
I am working on a project that involves writing some core
functionality in C/C++ and composing behavior in Guile (as I
understand it, this one of the ways that Guile was intended to be
used). However, I cannot load any libraries with dynamic-link. I first
encountered this with my code, but I'm going to use libc in my
examples since the error message is identical, libc is ubiquitous, and
it is the library that is given as an example in the manual. I am on
Arch Linux and I am fully upgraded; this is the error message that I
get:
ERROR: In procedure dynamic-link:
ERROR: in procedure dynamic-link: file "libc.so", message: "file not
found"
I've seen dynamic-link called with and without the 'so' prefix in
various places, so I have tried using "c", "libc", and "libc.so" as
the argument in my call to dynamic-link. They all produced the same
error message. Other people with a similar problem have been asked to
show the output of `ldd -r` or `ldd -d`. Both of them give me the same
output:
ldd: warning: you do not have execute permission for "/lib/libc.so"not
a dynamic executable
Do you know why this error would occur? Any help you can give me would
be appreciated.
Thanks,saffronsnail


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Can't use dynamic-link with any shared object file
  2016-12-26 17:25 Can't use dynamic-link with any shared object file saffronsnail
@ 2016-12-26 22:24 ` Jan Wedekind
  2016-12-27  1:17   ` saffronsnail
  2016-12-27  6:18   ` Eli Zaretskii
  2016-12-26 22:26 ` Chris Vine
  2016-12-26 23:18 ` spk121
  2 siblings, 2 replies; 6+ messages in thread
From: Jan Wedekind @ 2016-12-26 22:24 UTC (permalink / raw)
  To: saffronsnail; +Cc: guile-user

On Mon, 26 Dec 2016, saffronsnail@hushmail.com wrote:

> Hello,
> I am working on a project that involves writing some core
> functionality in C/C++ and composing behavior in Guile (as I
> understand it, this one of the ways that Guile was intended to be
> used). However, I cannot load any libraries with dynamic-link. I first
> encountered this with my code, but I'm going to use libc in my
> examples since the error message is identical, libc is ubiquitous, and
> it is the library that is given as an example in the manual. I am on
> Arch Linux and I am fully upgraded; this is the error message that I
> get:
> ERROR: In procedure dynamic-link:
> ERROR: in procedure dynamic-link: file "libc.so", message: "file not
> found"
> I've seen dynamic-link called with and without the 'so' prefix in
> various places, so I have tried using "c", "libc", and "libc.so" as
> the argument in my call to dynamic-link. They all produced the same
> error message. Other people with a similar problem have been asked to
> show the output of `ldd -r` or `ldd -d`. Both of them give me the same
> output:
> ldd: warning: you do not have execute permission for "/lib/libc.so"not
> a dynamic executable
> Do you know why this error would occur? Any help you can give me would
> be appreciated.
> Thanks,saffronsnail
>

I think "libc" is normally loaded already. E.g. the C function "abs" can 
be accessed as follows:

     (define main (dynamic-link))
     (define cabs (pointer->procedure long (dynamic-func "abs" main) (list long)))
     (cabs -42)
     ; 42

Regards
Jan



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Can't use dynamic-link with any shared object file
  2016-12-26 17:25 Can't use dynamic-link with any shared object file saffronsnail
  2016-12-26 22:24 ` Jan Wedekind
@ 2016-12-26 22:26 ` Chris Vine
  2016-12-26 23:18 ` spk121
  2 siblings, 0 replies; 6+ messages in thread
From: Chris Vine @ 2016-12-26 22:26 UTC (permalink / raw)
  To: guile-user

On Mon, 26 Dec 2016 09:25:00 -0800
saffronsnail@hushmail.com wrote:
> Hello, 
> I am working on a project that involves writing some core
> functionality in C/C++ and composing behavior in Guile (as I
> understand it, this one of the ways that Guile was intended to be
> used). However, I cannot load any libraries with dynamic-link. I first
> encountered this with my code, but I'm going to use libc in my
> examples since the error message is identical, libc is ubiquitous, and
> it is the library that is given as an example in the manual. I am on
> Arch Linux and I am fully upgraded; this is the error message that I
> get:
> ERROR: In procedure dynamic-link:
> ERROR: in procedure dynamic-link: file "libc.so", message: "file not
> found"
> I've seen dynamic-link called with and without the 'so' prefix in
> various places, so I have tried using "c", "libc", and "libc.so" as
> the argument in my call to dynamic-link. They all produced the same
> error message. Other people with a similar problem have been asked to
> show the output of `ldd -r` or `ldd -d`. Both of them give me the same
> output:
> ldd: warning: you do not have execute permission for "/lib/libc.so"not
> a dynamic executable
> Do you know why this error would occur? Any help you can give me would
> be appreciated.
> Thanks,saffronsnail

As regards libc, on a glibc/linux system the error you report is
correct.  libc.so is not linkable.  It is in fact a text file - do
'cat /usr/lib/libc.so' to see.  The one you are looking for is
libc.so.6, which is a dynamically executable.

As regards your own libraries, who knows?  Probably you did not build
them as relocatable shared libraries correctly.  If dynamic-link works
but your guile code cannot find its contents, possibly you have not
exported your C++ libraries with C linkage (that is, as extern "C") to
suppress name mangling.  Beyond saying that you must have done something
wrong, it is not possible to say what the problem is.

Chris



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Can't use dynamic-link with any shared object file
  2016-12-26 17:25 Can't use dynamic-link with any shared object file saffronsnail
  2016-12-26 22:24 ` Jan Wedekind
  2016-12-26 22:26 ` Chris Vine
@ 2016-12-26 23:18 ` spk121
  2 siblings, 0 replies; 6+ messages in thread
From: spk121 @ 2016-12-26 23:18 UTC (permalink / raw)
  To: saffronsnail, guile-user

‎Usually the strace command or setting the LD_DEBUG=all environment variable can provide useful info. They often reveal that I should have the LD_LIBRARY_PATH differently.

An annoyance of dynamic linking is that you also need to make sure that each shared object's own shared object dependencies are in the library path. Often when dynamic linking is complaining about something at appears to clearly exist, it is this recursive linking that is the problem.
‎



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Can't use dynamic-link with any shared object file
  2016-12-26 22:24 ` Jan Wedekind
@ 2016-12-27  1:17   ` saffronsnail
  2016-12-27  6:18   ` Eli Zaretskii
  1 sibling, 0 replies; 6+ messages in thread
From: saffronsnail @ 2016-12-27  1:17 UTC (permalink / raw)
  To: guile-user

On 12/26/2016 at 2:24 PM, "Jan Wedekind"  wrote:I think "libc" is
normally loaded already. E.g. the C function "abs" can 
be accessed as follows:

     (define main (dynamic-link))
     (define cabs (pointer->procedure long (dynamic-func "abs" main)
(list long)))
     (cabs -42)
     ; 42

Regards
Jan
You're right, the code works on my machine. It turns out that I was
looking at the 1.8 manual, rather than the 2.0 manual, which is why I
had the dated reference to libc. The new manual references libGL,
which I am able to link to.
On 12/26/2016 at 3:18 PM, spk121@yahoo.com wrote:‎Usually the strace
command or setting the LD_DEBUG=all environment variable can provide
useful info. They often reveal that I should have the LD_LIBRARY_PATH
differently.

An annoyance of dynamic linking is that you also need to make sure
that each shared object's own shared object dependencies are in the
library path. Often when dynamic linking is complaining about
something at appears to clearly exist, it is this recursive linking
that is the problem.
‎LD_DEBUG=all did it! I use Boost in the project, and I thought that
it was going to be linked into my shared object statically, but it
looks like I need to change my cmake file to make that happen. I wish
it told you *which* file was missing, as when it says `file
"libbutler", message: "file not found"` it really does sound like
libbutler is the file that can't be found (though in hindsight it's
pretty clear what they mean).
Thanks for the help!


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Can't use dynamic-link with any shared object file
  2016-12-26 22:24 ` Jan Wedekind
  2016-12-27  1:17   ` saffronsnail
@ 2016-12-27  6:18   ` Eli Zaretskii
  1 sibling, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2016-12-27  6:18 UTC (permalink / raw)
  To: Jan Wedekind; +Cc: saffronsnail, guile-user

> Date: Mon, 26 Dec 2016 22:24:21 +0000 (GMT)
> From: Jan Wedekind <jan@wedesoft.de>
> Cc: guile-user@gnu.org
> 
> I think "libc" is normally loaded already. E.g. the C function "abs" can 
> be accessed as follows:
> 
>      (define main (dynamic-link))
>      (define cabs (pointer->procedure long (dynamic-func "abs" main) (list long)))
>      (cabs -42)
>      ; 42

This is non-portable, and doesn't work outside of the Posix world.
E.g., on MS-Windows (with Guile 2.0.x):

  D:\usr\eli\data>guile
  GNU Guile 2.0.11
  Copyright (C) 1995-2014 Free Software Foundation, Inc.

  Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'.
  This program is free software, and you are welcome to redistribute it
  under certain conditions; type `,show c' for details.

  Enter `,help' for help.
  scheme@(guile-user)> ,use (system foreign)
  scheme@(guile-user)> ,use (rnrs bytevectors)
  scheme@(guile-user)> (define main (dynamic-link))
  scheme@(guile-user)> (define cabs (pointer->procedure long (dynamic-func "abs" main) (list long)))
  ERROR: In procedure dynamic-func:
  ERROR: In procedure dynamic-pointer: Symbol not found: abs

  Entering a new prompt.  Type `,bt' for a backtrace or `,q' to continue.
  scheme@(guile-user) [1]> ,q

But (msvcrt.dll is the C runtime library on Windows):

  scheme@(guile-user)> (define libc (dynamic-link "msvcrt.dll"))
  scheme@(guile-user)> (define cabs (pointer->procedure long (dynamic-func "abs" libc) (list long)))
  scheme@(guile-user)> (cabs -42)
  $1 = 42
  scheme@(guile-user)>



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-12-27  6:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-26 17:25 Can't use dynamic-link with any shared object file saffronsnail
2016-12-26 22:24 ` Jan Wedekind
2016-12-27  1:17   ` saffronsnail
2016-12-27  6:18   ` Eli Zaretskii
2016-12-26 22:26 ` Chris Vine
2016-12-26 23:18 ` spk121

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).