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

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  8:13 C module problem 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
  -- strict thread matches above, loose matches on Subject: below --
2011-02-28  9:40 nalaginrut
2011-02-28 10:16 ` rm
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

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