From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Tomas By" Newsgroups: gmane.lisp.guile.user Subject: loading a module Date: Wed, 17 Feb 2010 19:26:54 +0100 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1266431261 31847 80.91.229.12 (17 Feb 2010 18:27:41 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 17 Feb 2010 18:27:41 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Feb 17 19:27:39 2010 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Nhocc-0003JP-71 for guile-user@m.gmane.org; Wed, 17 Feb 2010 19:27:38 +0100 Original-Received: from localhost ([127.0.0.1]:40664 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nhocb-0004q4-Fz for guile-user@m.gmane.org; Wed, 17 Feb 2010 13:27:37 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nhoc1-0004hj-La for guile-user@gnu.org; Wed, 17 Feb 2010 13:27:01 -0500 Original-Received: from [140.186.70.92] (port=40953 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nhoc0-0004h6-Ip for guile-user@gnu.org; Wed, 17 Feb 2010 13:27:01 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Nhoby-0001TW-Ep for guile-user@gnu.org; Wed, 17 Feb 2010 13:27:00 -0500 Original-Received: from smtp-vbr9.xs4all.nl ([194.109.24.29]:1048) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Nhoby-0001Su-7Z for guile-user@gnu.org; Wed, 17 Feb 2010 13:26:58 -0500 Original-Received: from webmail.xs4all.nl (dovemail15.xs4all.nl [194.109.26.17]) by smtp-vbr9.xs4all.nl (8.13.8/8.13.8) with ESMTP id o1HIQsCE072904 for ; Wed, 17 Feb 2010 19:26:54 +0100 (CET) (envelope-from tomas@basun.net) Original-Received: from 89.152.179.129 (SquirrelMail authenticated user tby) by webmail.xs4all.nl with HTTP; Wed, 17 Feb 2010 19:26:54 +0100 User-Agent: SquirrelMail/1.4.18 X-Virus-Scanned: by XS4ALL Virus Scanner X-detected-operating-system: by eggs.gnu.org: FreeBSD 4.6-4.9 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:7645 Archived-At: 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 # $ 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 SCM testproc_wrapper(SCM,SCM); void init_mytest(void); #endif /* MYDEF_H */ ---------- mytest.c -------------------------------------------------- #include #include #include "mylibrary.h" #include "mylib.mh" #include "mytest.h" #include 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 #include #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 # # #] ?: 21* [#] ?: 22* (let* ((file #)) (cond (# => #) (# => #))) ?: 23 [# "/usr/share/guile/1.8/mytest.scm"] ?: 24 [with-fluid* # #f #] ?: 25* [#] ?: 26* [load-file # ...] ?: 27* [save-module-excursion #] ?: 28 (let (# #) (dynamic-wind # thunk #)) ?: 29 [dynamic-wind # # #] ?: 30* [#] ?: 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> ----------------------------------------------------------------------