unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* C module problem
@ 2011-02-28  8:13 Aidan Gauland
  2011-02-28  8:54 ` nalaginrut
  2011-02-28 21:37 ` Andy Wingo
  0 siblings, 2 replies; 12+ messages in thread
From: Aidan Gauland @ 2011-02-28  8:13 UTC (permalink / raw)
  To: guile-user


[-- Attachment #1.1: Type: text/plain, Size: 713 bytes --]

Hello,

I am trying to write a simple C module for Guile (for the learning
experience) and I have run into a cryptic error.  I have compiled
`sdl-guile.c' to `sdl-guile.so' with the following command.

gcc -shared -o sdl-guile.so -fPIC sdl-guile.c `guile-config compile` `sdl-config --cflags`

I then run `guile' and evaluate
(load-extension "./sdl-guile.so" "init_module") and get the following
output.

ERROR: In procedure load-extension:
ERROR: In procedure dynamic-link: file: "./sdl-guile.so", message: "file not found"

I can follow the example in section 6.20.3 C Extensions of the manual
with no trouble, so I think I am not properly linking to SDL.

Can anyone help me with this?

Regards,
Aidan Gauland

[-- Attachment #1.2: sdl-guile.c --]
[-- Type: text/x-csrc, Size: 669 bytes --]

#include <libguile.h>
#include "SDL.h"

void init_video();

void init_module()
{
	/* Initialize SDL. */
	if (SDL_Init(SDL_INIT_VIDEO) != 0) {
		fprintf(stderr, "SDL initialization error: %s\n", SDL_GetError());
		exit(EXIT_FAILURE);
	}
	/* SDL_Quit should be called when the program finishes. */	
	atexit(SDL_Quit);

	/* Register guile procedures. */
	scm_c_define_gsubr("init-video", 0, 0, 0, init_video);
}

void init_video()
{
	/* Set up video. */
	SDL_Surface *screen;
	screen = SDL_SetVideoMode(640, 480, 24, SDL_HWSURFACE);
	if (screen == NULL) {
		fprintf(stderr, "SDL video error: %s\n", SDL_GetError());
		exit(EXIT_FAILURE);
	}
}

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: C module problem
  2011-02-28  8:13 Aidan Gauland
@ 2011-02-28  8:54 ` nalaginrut
  2011-02-28  9:32   ` Aidan Gauland
  2011-02-28 21:37 ` Andy Wingo
  1 sibling, 1 reply; 12+ messages in thread
From: nalaginrut @ 2011-02-28  8:54 UTC (permalink / raw)
  To: Aidan Gauland; +Cc: guile-user

> Hello,
> 
> I am trying to write a simple C module for Guile (for the learning
> experience) and I have run into a cryptic error.  I have compiled
> `sdl-guile.c' to `sdl-guile.so' with the following command.
> 
> gcc -shared -o sdl-guile.so -fPIC sdl-guile.c `guile-config compile` `sdl-config --cflags`
> 
> I then run `guile' and evaluate
> (load-extension "./sdl-guile.so" "init_module") and get the following
> output.
> 
> ERROR: In procedure load-extension:
> ERROR: In procedure dynamic-link: file: "./sdl-guile.so", message: "file not found"
> 
> I can follow the example in section 6.20.3 C Extensions of the manual
> with no trouble, so I think I am not properly linking to SDL.
> 
> Can anyone help me with this?
> 
> Regards,
> Aidan Gauland

hi, you may type ",d load-extension" in the repl environment.
And you will find this note:
=======================================
LIB should be a string denoting a shared library without any file
type suffix such as ".so".
=======================================

-- 
GNU Powered it
GPL Protected it
GOD Blessed it

HFG - NalaGinrut




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

* Re: C module problem
  2011-02-28  8:54 ` nalaginrut
@ 2011-02-28  9:32   ` Aidan Gauland
  0 siblings, 0 replies; 12+ messages in thread
From: Aidan Gauland @ 2011-02-28  9:32 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 1380 bytes --]

On Mon, Feb 28, 2011 at 04:54:00PM +0800, nalaginrut wrote:
> > I then run `guile' and evaluate
> > (load-extension "./sdl-guile.so" "init_module") and get the following
> > output.
> > 
> > ERROR: In procedure load-extension:
> > ERROR: In procedure dynamic-link: file: "./sdl-guile.so", message: "file not found"
> > 
> > I can follow the example in section 6.20.3 C Extensions of the manual
> > with no trouble, so I think I am not properly linking to SDL.
> > 
> > Can anyone help me with this?
> > 
> > Regards,
> > Aidan Gauland
> 
> hi, you may type ",d load-extension" in the repl environment.
> And you will find this note:
> =======================================
> LIB should be a string denoting a shared library without any file
> type suffix such as ".so".
> =======================================

Oops, forgot to omit the ".so".  That doesn't seem to be the problem, thoug=
h.

scheme@(guile-user)> (load-extension "sdl-guile" "init_module")
ERROR: In procedure load-extension:
ERROR: In procedure dynamic-link: file: "sdl-guile", message: "file not fou=
nd"

scheme@(guile-user)> (load-extension "./sdl-guile" "init_module")
ERROR: In procedure load-extension:
ERROR: In procedure dynamic-link: file: "./sdl-guile", message: "file not f=
ound"

I am running it from the same directory as the file "sdl-guile.so".

--Aidan

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: C module problem
@ 2011-02-28  9:40 nalaginrut
  2011-02-28 10:16 ` rm
  0 siblings, 1 reply; 12+ messages in thread
From: nalaginrut @ 2011-02-28  9:40 UTC (permalink / raw)
  To: guile-user

> On Mon, Feb 28, 2011 at 04:54:00PM +0800, nalaginrut wrote:
> > > I then run `guile' and evaluate
> > > (load-extension "./sdl-guile.so" "init_module") and get the following
> > > output.
> > > 
> > > ERROR: In procedure load-extension:
> > > ERROR: In procedure dynamic-link: file: "./sdl-guile.so", message: "file not found"
> > 
> > hi, you may type ",d load-extension" in the repl environment.
> > And you will find this note:
> > =======================================
> > LIB should be a string denoting a shared library without any file
> > type suffix such as ".so".
> > =======================================
> 
> Oops, forgot to omit the ".so".  That doesn't seem to be the problem, though.
> 
> scheme@(guile-user)> (load-extension "sdl-guile" "init_module")
> ERROR: In procedure load-extension:
> ERROR: In procedure dynamic-link: file: "sdl-guile", message: "file not found"
> 
> scheme@(guile-user)> (load-extension "./sdl-guile" "init_module")
> ERROR: In procedure load-extension:
> ERROR: In procedure dynamic-link: file: "./sdl-guile", message: "file not found"
> 
> I am running it from the same directory as the file "sdl-guile.so".
> 
> --Aidan

You should read the document continuously. :-)
=================================
     LIB should be a string denoting a shared library without any file
     type suffix such as ".so".  The suffix is provided automatically.
     It should also not contain any directory components.  Libraries
     that implement Guile Extensions should be put into the normal
     locations for shared libraries.
=================================
So I think you must copy the share lib into the lib directory. 



-- 
GNU Powered it
GPL Protected it
GOD Blessed it

HFG - NalaGinrut




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

* Re: C module problem
  2011-02-28  9:40 C module problem nalaginrut
@ 2011-02-28 10:16 ` rm
  0 siblings, 0 replies; 12+ messages in thread
From: rm @ 2011-02-28 10:16 UTC (permalink / raw)
  To: nalaginrut; +Cc: guile-user

On Mon, Feb 28, 2011 at 05:40:12PM +0800, nalaginrut wrote:
> > On Mon, Feb 28, 2011 at 04:54:00PM +0800, nalaginrut wrote:
> > > > I then run `guile' and evaluate
> > > > (load-extension "./sdl-guile.so" "init_module") and get the following
> > > > output.
> > > > 
> > > > ERROR: In procedure load-extension:
> > > > ERROR: In procedure dynamic-link: file: "./sdl-guile.so", message: "file not found"
> > > 
> > > hi, you may type ",d load-extension" in the repl environment.
> > > And you will find this note:
> > > =======================================
> > > LIB should be a string denoting a shared library without any file
> > > type suffix such as ".so".
> > > =======================================
> > 
> > Oops, forgot to omit the ".so".  That doesn't seem to be the problem, though.
> > 
> > scheme@(guile-user)> (load-extension "sdl-guile" "init_module")
> > ERROR: In procedure load-extension:
> > ERROR: In procedure dynamic-link: file: "sdl-guile", message: "file not found"
> > 
> > scheme@(guile-user)> (load-extension "./sdl-guile" "init_module")
> > ERROR: In procedure load-extension:
> > ERROR: In procedure dynamic-link: file: "./sdl-guile", message: "file not found"
> > 
> > I am running it from the same directory as the file "sdl-guile.so".
> > 
> > --Aidan
> 
> You should read the document continuously. :-)
> =================================
>      LIB should be a string denoting a shared library without any file
>      type suffix such as ".so".  The suffix is provided automatically.
>      It should also not contain any directory components.  Libraries
>      that implement Guile Extensions should be put into the normal
>      locations for shared libraries.
> =================================
> So I think you must copy the share lib into the lib directory. 

Yes, that's the most obvious way but it should work with a ful pathname
as well. Note: './foo' isn't a full pathname - something like:

   (load-extension (string-append (getcwd) "/sdl-guile") "init_module")

should work.

 HTH Ralf Mattes

> 
> 
> -- 
> GNU Powered it
> GPL Protected it
> GOD Blessed it
> 
> HFG - NalaGinrut
> 



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

* Re: C module problem
@ 2011-02-28 14:54 Mike Gran
  2011-02-28 15:35 ` gustav
  2011-02-28 17:30 ` dsmich
  0 siblings, 2 replies; 12+ messages in thread
From: Mike Gran @ 2011-02-28 14:54 UTC (permalink / raw)
  To: Aidan Gauland, guile-user@gnu.org

> From:Aidan Gauland <aidalgol@no8wireless.co.nz>


> Hello,

Hi Aidan,

> 
> I am trying to write a simple C module for Guile (for the learning
> experience) and I have run into a cryptic error.  I have compiled
> `sdl-guile.c' to `sdl-guile.so' with the following command.
> 
> gcc -shared -o sdl-guile.so -fPIC sdl-guile.c `guile-config compile` `sdl-config 
> --cflags`
> 
> I then run `guile' and evaluate
> (load-extension "./sdl-guile.so" "init_module") and get the 
> following
> output.
> 
> ERROR: In procedure load-extension:
> ERROR: In procedure dynamic-link: file: "./sdl-guile.so", message: 
> "file not found"

If you are getting this error when you've done everything right
with paths and filenames, it may indicate that the file is being
found, but, that there are some other error errors that keep it
from being loaded.

On Linux (the kernel), to see if this is the case (and I'm going
from memory here, so forgive me if this isn't perfect) you can
run guile as

"LD_DEBUG=all LD_DEBUG_OUTPUT=tmp.txt guile"

and then try to load your extension.

Then after your run, it should have made a handful of tmp.txt files, one
per thread.  Search through these files for strings like "error" or "fatal"
with reference to your binding.  It may be that you've misspelled a function
name or are trying to link to a function that doesn't exist.

For more info on this, check out the man page to ld-linux.so

Hope this helps,

-Mike Gran



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

* Re: C module problem
  2011-02-28 14:54 Mike Gran
@ 2011-02-28 15:35 ` gustav
  2011-02-28 17:30 ` dsmich
  1 sibling, 0 replies; 12+ messages in thread
From: gustav @ 2011-02-28 15:35 UTC (permalink / raw)
  To: spk121; +Cc: guile-user


> I am trying to write a simple C module for Guile (for the learning
> experience) and I have run into a cryptic error.  I have compiled
> `sdl-guile.c' to `sdl-guile.so' with the following command.
> 
> gcc -shared -o sdl-guile.so -fPIC sdl-guile.c `guile-config compile` `sdl-config 
> --cflags`
> 
> I then run `guile' and evaluate
> (load-extension "./sdl-guile.so" "init_module") and get the 
> following
> output.
> 
> ERROR: In procedure load-extension:
> ERROR: In procedure dynamic-link: file: "./sdl-guile.so", message: 
> "file not found"

I've seen similar errors in the past, exactly in the same
context. They mostly had to do with Guile unable to find the file,
because you *must* give it a full path. The "load-extension" function
does not seem to understand "./", or other similar UNIXy tricks, e.g.,
"~/", "../", etc.

Here is, for example, what I had to do to make it load in one case:

(define libguile_gsl "/home/gustav/src/Forms/lib/libguile_gsl")
(define libguile_gsl_file (string-join (list libguile_gsl "dll") "." 'infix))
(if (access? libguile_gsl_file (logior R_OK X_OK))
   (load-extension libguile_gsl "init_gsl"))

Another, more universal example:

(define SYSTEM (utsname:sysname (uname)))
(cond
 ((equal? SYSTEM "Linux") 
  (define DLIB_EXT ".so")
  (define LIB "/fusion/gpfs/project/photonic/lib/Forms"))
 ((equal? SYSTEM "CYGWIN_NT-6.0-WOW64")
  (define DLIB_EXT ".dll")
  (define LIB (string-append (getenv "HOME") "/src/Forms/lib")))
 (#t 
  (define DLIB_EXT "")
  (define LIB "")))
...
(load-extension (string-append LIB "/harmonic" DLIB_EXT) "init_signal_lambdas")
(load-extension (string-append LIB "/drude" DLIB_EXT) "init_e_lambda")

Hope this helps,
Cheers,

Zdzislaw (Gustav) Meglicki, Office of the Vice President for Information
Technology, Indiana University, 601 E. Kirkwood Ave., Room 116, 
Bloomington, IN 47405-1223, USA, http://perth.ovpit.indiana.edu/gustav,
Ph: 812-856-5597 (o), 812-345-3284 (m), Fax: 812-855-3310/812-856-3147,
Skype: zdzislaw.meglicki




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

* Re: C module problem
  2011-02-28 14:54 Mike Gran
  2011-02-28 15:35 ` gustav
@ 2011-02-28 17:30 ` dsmich
  2011-02-28 18:24   ` Aidan Gauland
  1 sibling, 1 reply; 12+ messages in thread
From: dsmich @ 2011-02-28 17:30 UTC (permalink / raw)
  To: Aidan Gauland, Mike Gran, guile-user@gnu.org


---- Mike Gran <spk121@yahoo.com> wrote: 

> On Linux (the kernel), to see if this is the case (and I'm going
> from memory here, so forgive me if this isn't perfect) you can
> run guile as
> 
> "LD_DEBUG=all LD_DEBUG_OUTPUT=tmp.txt guile"
> 
> and then try to load your extension.
> 
> Then after your run, it should have made a handful of tmp.txt files, one
> per thread.  Search through these files for strings like "error" or "fatal"
> with reference to your binding.  It may be that you've misspelled a function
> name or are trying to link to a function that doesn't exist.

It is also instructive to run the command under strace -efile.  You get a clear idea of what file guile *is* trying to open and *where*.

I've solved more "can't open the file" type problems with strace than I can remember.  A wonderful tool.

-Dale




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

* Re: C module problem
  2011-02-28 17:30 ` dsmich
@ 2011-02-28 18:24   ` Aidan Gauland
  2011-02-28 20:43     ` Aidan Gauland
  0 siblings, 1 reply; 12+ messages in thread
From: Aidan Gauland @ 2011-02-28 18:24 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 635 bytes --]

On Mon, Feb 28, 2011 at 12:30:31PM -0500, dsmich@roadrunner.com wrote:
> It is also instructive to run the command under strace -efile.  You get a clear idea of what file guile *is* trying to open and *where*.
> 
> I've solved more "can't open the file" type problems with strace than I can remember.  A wonderful tool.

I am *certain* it is not a problem with using ./ notation, because I
can follow an example from the Guile manual that uses it with no
problem.

I'll do as you say, and run it under strace.

How do Guile bindings link to the libraries they bind?  That's more or
less what I am trying to do.

--Aidan

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: C module problem
  2011-02-28 18:24   ` Aidan Gauland
@ 2011-02-28 20:43     ` Aidan Gauland
  0 siblings, 0 replies; 12+ messages in thread
From: Aidan Gauland @ 2011-02-28 20:43 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 423 bytes --]

On Tue, Mar 01, 2011 at 07:24:51AM +1300, Aidan Gauland wrote:
> How do Guile bindings link to the libraries they bind?  That's more or
> less what I am trying to do.

Actually, scratch that.  I just discovered Guile2's FFI.  I can
probably figure out how to use it by digging through the manual and
fiddling with Guile, but is there already an approved or recommended way to
use Guile's FFI that I should follow?

--Aidan

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

* Re: C module problem
  2011-02-28  8:13 Aidan Gauland
  2011-02-28  8:54 ` nalaginrut
@ 2011-02-28 21:37 ` Andy Wingo
  2011-02-28 23:23   ` Aidan Gauland
  1 sibling, 1 reply; 12+ messages in thread
From: Andy Wingo @ 2011-02-28 21:37 UTC (permalink / raw)
  To: guile-user

Hi Aidan,

On Mon 28 Feb 2011 09:13, Aidan Gauland <aidalgol@no8wireless.co.nz> writes:

> I am trying to write a simple C module for Guile (for the learning
> experience) and I have run into a cryptic error.

Apologies for this.  It is actually a libltdl issue:

  "As I am sure many are aware, libltdl's error reporting is pretty
  dumb, lt_dlerror() regularly reports things like "file not found"
  where the actual problem might be something completely different, and
  a reasonable error string may be readily available from dlerror()."

  http://lists.gnu.org/archive/html/libtool/2010-06/msg00056.html

> gcc -shared -o sdl-guile.so -fPIC sdl-guile.c `guile-config compile` `sdl-config --cflags`

In this case loading the library fails probably because you did not add
SDL libs.  `sdl-config --cflags --libs` perhaps?  Just a guess.

That said, the dynamic FFI is more fun; and also, there is a guile-sdl
package out there somewhere.

Cheers,

Andy
-- 
http://wingolog.org/



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

* Re: C module problem
  2011-02-28 21:37 ` Andy Wingo
@ 2011-02-28 23:23   ` Aidan Gauland
  0 siblings, 0 replies; 12+ messages in thread
From: Aidan Gauland @ 2011-02-28 23:23 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 987 bytes --]

On Mon, Feb 28, 2011 at 10:37:28PM +0100, Andy Wingo wrote:
> Apologies for this.  It is actually a libltdl issue:
> 
>   "As I am sure many are aware, libltdl's error reporting is pretty
>   dumb, lt_dlerror() regularly reports things like "file not found"
>   where the actual problem might be something completely different, and
>   a reasonable error string may be readily available from dlerror()."
> 
>   http://lists.gnu.org/archive/html/libtool/2010-06/msg00056.html
> 
> In this case loading the library fails probably because you did not add
> SDL libs.  `sdl-config --cflags --libs` perhaps?  Just a guess.

Ah, OK, that did it.  Thanks!

> That said, the dynamic FFI is more fun;

I'll just use the FFI, since it's there.

> and also, there is a guile-sdl package out there somewhere.

I found one on Savannah, but it failed to build, saying it could not
find some header file.  But I'd rather use Guile's FFI (now that I
know it's there).

--Aidan

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

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

end of thread, other threads:[~2011-02-28 23:23 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-28  9:40 C module problem nalaginrut
2011-02-28 10:16 ` rm
  -- strict thread matches above, loose matches on Subject: below --
2011-02-28 14:54 Mike Gran
2011-02-28 15:35 ` gustav
2011-02-28 17:30 ` dsmich
2011-02-28 18:24   ` Aidan Gauland
2011-02-28 20:43     ` Aidan Gauland
2011-02-28  8:13 Aidan Gauland
2011-02-28  8:54 ` nalaginrut
2011-02-28  9:32   ` Aidan Gauland
2011-02-28 21:37 ` Andy Wingo
2011-02-28 23:23   ` Aidan Gauland

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).