Rcjp's Weblog

June 2, 2006

Using a shared lib from cmucl

Filed under: c, lisp, unix — rcjp @ 1:24 pm

library code mylib2.c

#include <stdio.h>

int mytest()
    printf("inside c lib !!!\n");
    return 2;


(defun fact (n)
  (if (= n 1)
      (* n (fact (- n 1)))))

(ext:load-foreign "/usr/local/lib/libmylib2.so.1")
(alien:alien-funcall (alien:extern-alien "mytest" (function c-call:void) ))


#include <stdio.h>

int main()
    printf("inside main program\n");
    printf("back inside main program\n");

build using

cc -fPIC -c mylib2.c
gcc -shared -Wl,-soname,libmylib2.so.1 -o libmylib2.so.1   mylib2.o
# now use the lib
# need to copy libmylib2.so.1 to /usr/local/lib or somewhere
# then as root do 'ldconfig' 
cc test2.c -L. -lmylib2.so.1 -o test2


Leave a Comment »

No comments yet.

RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: