C module problem

2011-02-28 Thread Aidan Gauland
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
#include 
#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);
	}
}


signature.asc
Description: Digital signature


Re: C module problem

2011-02-28 Thread nalaginrut
> 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




Re: C module problem

2011-02-28 Thread Aidan Gauland
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


signature.asc
Description: Digital signature


Re: C module problem

2011-02-28 Thread nalaginrut
> 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




Re: C module problem

2011-02-28 Thread rm
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
> 



Re: C module problem

2011-02-28 Thread Mike Gran
> From:Aidan Gauland 


> 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



Re: C module problem

2011-02-28 Thread gustav

> 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




Re: C module problem

2011-02-28 Thread dsmich

 Mike Gran  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




Re: C module problem

2011-02-28 Thread Aidan Gauland
On Mon, Feb 28, 2011 at 12:30:31PM -0500, dsm...@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


signature.asc
Description: Digital signature


Re: C module problem

2011-02-28 Thread Aidan Gauland
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


signature.asc
Description: Digital signature


Re: C module problem

2011-02-28 Thread Andy Wingo
Hi Aidan,

On Mon 28 Feb 2011 09:13, Aidan Gauland  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/



Re: [r6rs] expansion bug, probably free-identifier=? related

2011-02-28 Thread Andy Wingo
Indeed, it seems free-id=? should look up the identifiers in their
modules, and compare the bindings (variables), if present, for
eq?-ness.

Andy
-- 
http://wingolog.org/



Re: C module problem

2011-02-28 Thread Aidan Gauland
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


signature.asc
Description: Digital signature


FFI nuisance

2011-02-28 Thread Aidan Gauland
Hi,

I'm trying to use SDL through Guile's dynamic FFI.  There's a slight
nuisance with the procedure `dynamic-link': the name of the so file on
my system (Debian squeeze) is `libSDL-1.2.so.0', so because of the
`.0' at the end, (dynamic-link "libSDL-1.2") fails to find the file,
even if I give it the full path name (dynamic-link
"/usr/lib/libSDL-1.2.so.0").

I can work around this by making a symlink `libSDL-1.2.so' to
`libSDL-1.2.so.0'.  I really think that it should be possible to load
a so file that doesn't end in .so without having to touch the
filesystem.  Is there a way to do this, or should I submit a feature
request?

Regards,
Aidan Gauland


signature.asc
Description: Digital signature