[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
loading a module
From: |
Tomas By |
Subject: |
loading a module |
Date: |
Wed, 17 Feb 2010 19:26:54 +0100 |
User-agent: |
SquirrelMail/1.4.18 |
Hello one more time,
There was a little problem in mytest.c, where I had declared a pointer
only and no address location. This was the cause of the segmentation
fault.
With the following source files, the code Linas posted, after some
modifications, is compiled to a binary `vepstas' which runs fine with
no errors:
$ ./vepstas
#<mytype b7736510>
$
Trying to load the Guile module, however, still fails.
I think the "file not found" message is just the general dynamic-link-
anything error.
Any help much appreciated...
(Guile 1.8.7)
/Tomas
---------- mytest.scm ------------------------------------------------
(define-module (mytest))
(export mytest)
(load-extension "libguile-mytest" "init_mytest")
---------- mylib.m (Mercury) -----------------------------------------
:- module mylib.
:- interface.
:- use_module io.
:- import_module list,bool.
:- type mytype ---> stuff(int,float,bool).
:- pred testproc(list(string),mytype,io.state,io.state).
:- mode testproc(in,out,di,uo) is det.
:- implementation.
:- pragma foreign_export("C",testproc(in,out,di,uo),"testproc_c").
testproc(_,X,!IO) :- X = stuff(0,0.0,no).
:- end_module mylib.
---------- mytest.h --------------------------------------------------
#ifndef MYDEF_H
#define MYDEF_H
#include <libguile.h>
SCM testproc_wrapper(SCM,SCM);
void init_mytest(void);
#endif /* MYDEF_H */
---------- mytest.c --------------------------------------------------
#include <libguile.h>
#include <mercury.h>
#include "mylibrary.h"
#include "mylib.mh"
#include "mytest.h"
#include <stdio.h>
void init_mytest()
{
void *dummy;
char* args[1] = {(char*)""};
mercury_init(1,args,&dummy);
(void)scm_make_smob_type("mytype",0);
scm_c_define_gsubr("mytest",2,0,0,testproc_wrapper);
}
SCM testproc_wrapper(SCM s,SCM x)
{
MR_Word temp = MR_list_empty();
MR_Word p = NULL;
testproc_c(temp,&p);
SCM_SET_SMOB_DATA(x,(scm_t_bits)p);
return SCM_BOOL_T;
}
---------- mylib.mh --------------------------------------------------
/*
** Automatically generated from `mylib.m'
** by the Mercury compiler,
** version rotd-2009-12-28, configured for i686-pc-linux-gnu.
** Do not edit.
*/
#ifndef MYLIB_MH
#define MYLIB_MH
#ifdef __cplusplus
extern "C" {
#endif
#ifdef MR_HIGHLEVEL_CODE
#include "mercury.h"
#else
#ifndef MERCURY_HDR_EXCLUDE_IMP_H
#include "mercury_imp.h"
#endif
#endif
#ifdef MR_DEEP_PROFILING
#include "mercury_deep_profiling.h"
#endif
#ifndef MYLIB_DECL_GUARD
#define MYLIB_DECL_GUARD
#endif
void testproc_c(MR_Word, MR_Word *);
#ifdef __cplusplus
}
#endif
#endif /* MYLIB_MH */
---------- vepstas.c -------------------------------------------------
#include <libguile.h>
#include <mercury.h>
#include "mylibrary.h"
SCM testproc_wrapper(SCM,SCM);
int main(void)
{
char* args[1] = {(char*)""};
void *dummy;
SCM x;
scm_t_bits tag;
mercury_init(1,args,&dummy);
scm_init_guile();
tag = scm_make_smob_type("mytype",0);
SCM_NEWSMOB(x,tag,NULL);
(void)testproc_wrapper(scm_from_locale_string(""),x);
scm_display(x,scm_current_output_port());
scm_newline(scm_current_output_port());
return 0;
}
---------- Makefile --------------------------------------------------
nothing: lib
CC = gcc
LD = gcc
MMC = mmc
MMAKE = mmake
GUILE_CFLAGS=$(shell guile-config compile)
GUILE_LIBS=$(shell guile-config link)
MERCURY_CFLAGS=$(shell $(MMC) --output-cflags)
MERCURY_LIBS=$(shell $(MMC) --output-library-link-flags --mercury-linkage
shared)
CFLAGS = $(MERCURY_CFLAGS) $(GUILE_CFLAGS)
LIBS = $(MERCURY_LIBS) $(GUILE_LIBS)
LDFLAGS = -L. -Wl,-rpath . -lmylib
mylib.mh : mylib.m
$(MMC) --make mylib.mh
mylibrary.h mylibrary.o : mylib.m
$(MMC) --generate-standalone-interface mylibrary mylib.m
libmylib.so : mylib.m
$(MMC) --make libmylib
mytest.o : mytest.h mytest.c mylibrary.h mylib.mh
$(CC) -c mytest.c $(CFLAGS)
lib : mytest.o libmylib.so
$(LD) -shared -fPIC -o libguile-mytest.so mytest.o $(LDFLAGS) $(LIBS)
install : mytest.scm lib
sudo cp mytest.scm /usr/share/guile/1.8/
sudo cp libguile-mytest.so /usr/lib/
vepstas : vepstas.c lib mylibrary.o
$(CC) vepstas.c -o vepstas $(CFLAGS) mylibrary.o -lguile-mytest -L.
$(LDFLAGS) $(LIBS)
----------------------------------------------------------------------
guile> (use-modules (mytest))
Backtrace:
In unknown file:
...
?: 13 (begin (if # #) (make-modules-in # full-name))
?: 14* (if (or # #) (try-load-module name))
?: 15 [try-load-module (mytest)]
?: 16 (or (begin (try-module-linked name)) (try-module-autoload name)
...)
?: 17* [try-module-autoload (mytest)]
?: 18 (let* (# # # #) (resolve-module dir-hint-module-name #f) (and # #))
...
?: 19 (letrec ((load-file #)) (dynamic-wind (lambda () #) (lambda ()
#) ...) ...)
?: 20* [dynamic-wind #<procedure #f ()> #<procedure #f ()> #<procedure
#f ()>]
?: 21* [#<procedure #f ()>]
?: 22* (let* ((file #)) (cond (# => #) (# => #)))
?: 23 [#<procedure #f (full)> "/usr/share/guile/1.8/mytest.scm"]
?: 24 [with-fluid* #<fluid 7> #f #<procedure #f ()>]
?: 25* [#<procedure #f ()>]
?: 26* [load-file #<primitive-procedure primitive-load> ...]
?: 27* [save-module-excursion #<procedure #f ()>]
?: 28 (let (# #) (dynamic-wind # thunk #))
?: 29 [dynamic-wind #<procedure #f ()> #<procedure #f ()> #<procedure
#f ()>]
?: 30* [#<procedure #f ()>]
?: 31* [primitive-load "/usr/share/guile/1.8/mytest.scm"]
In /usr/share/guile/1.8/mytest.scm:
3: 32* [load-extension "libguile-mytest" "init_mytest"]
/usr/share/guile/1.8/mytest.scm:3:1: In procedure dynamic-link in
expression (load-extension "libguile-mytest" "init_mytest"):
/usr/share/guile/1.8/mytest.scm:3:1: file: "libguile-mytest", message:
"file not found"
ABORT: (misc-error)
guile>
----------------------------------------------------------------------
- loading a module,
Tomas By <=