I've recently acquired a copy of the new "Linux Application Development" by
Michael K. Johnson and Erik W. Troan.

In it, it describes how to create and use shared libraries. But when I follow
the instructions. It doesn't work.

Here is the example:


`libhello.c'
-------------------------------------------------------------------------------
#include <stdio.h>
void print_hello(void){
  printf("Hello, shared library.\n");
}
-------------------------------------------------------------------------------


`libhello.h' (this file was not included, but below is a best guess)
-------------------------------------------------------------------------------
void print_hello(void);
-------------------------------------------------------------------------------


`usehello.c'
-------------------------------------------------------------------------------
#include "libhello.h"
int main(void){
  print_hello();
  return 0;
}
-------------------------------------------------------------------------------


Compile and Link instructions:

gcc -fPIC -Wall -g -c libhello.c

gcc -g -shared -Wl,-soname,libhello.so.0 -o libhello.so.0.0 libhello.o -lc

ln -sf libhello.so.0.0 libhello.so.0

ln -sf libhello.so.0 libhello.so

gcc -Wall -g -c usehello.c -o usehello.o

gcc -g -o usehello usehello.o -L. -lhello


Then run with:

LD_LIBRARY_PATH='pwd' ./usehello


But I get this error:

./usehello: can't load library 'libhello.so.0'


Any suggestions?
Brock

+------------------------/----------------------------------------------------+
| R. Brock Lynn         /  http://citv.unl.edu/linux/LinuxPresentation.html   |
| [EMAIL PROTECTED]  / http://www.kirch.net/unix-nt.html  Live free or die. |
+---------------------/-------------------------------------------------------+

Reply via email to