[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: shared library tutorial?



Dale Martin wrote:
>Hello,
>
>	I have built a PCCTS source package - PCCTS is the "Purdue
>Compiler-Construction Tool Set" - it produces LL(K) parsers.  I'm
>using it in a project which I will eventually Debianize.  The PCCTS
>package is close to ready to upload, except it has some libraries in
>it, and I would like to compile them as shared libraries and don't
>know how.  (I'd also like to use shared libraries in my own project.)
>
>Can anyone point me to an online reference on how to compile and use
>shared libraries?  Note that I'm also interested in the portability of
>the solution - my project also is working with Linux/Alpha, and
>Solaris machines...
>
>Thanks for any info!
>
>	Dale
>

I don't know anything about the portability side but this seems
to work for me:

sophis.c:
/* a sophis-tercated example */

extern void grunt(char *);

int main()
{
	grunt("Hello world.\n");
}

tercated.c:
/* a sophis-tercated example */

#include<stdio.h>

void grunt(char * foo)
{
	printf(foo);
}

And then:

$ gcc --shared -o libgrunt.so tercated.c

(as root)
# cp libgrunt.so /usr/local/lib/
# ldconfig -v

$ gcc -o sophis sophis.c -lgrunt
$ ./sophis
Hello world.
$

I suppose there is more to it than this -- depending on your
application -- but I don't know what.  The path /usr/local/lib
has to be in the configuration in /etc/ld.conf and should not
be /usr/local/lib if you are actually making a ".deb".


--kmb203@psu.edu----------------Debian/GNU--1.2---Linux--2.1.25---
<kmb203@psu.edu>  <bealer@cse.psu.edu>  <kmb203@kmb203.rh.psu.edu> 
------------------------------------------------------------------
A computer lets you make more mistakes faster than any other
invention, with the possible exceptions of handguns and Tequilla.
	-- Mitch Ratcliffe


Reply to: