ch2-test

Chapter_2     readfile tiff







CONTENTS:     test.h     test.c     app.c




test.h


int f ();





test.c     ALP, p. 43-45


#include "test.h"

int f ()
{
return 3;
}
/*
gcc -c test.c
ar cr libtest.a test.o

gcc -c -fPIC test.c
gcc -shared -fPIC test.o -o libtest.so
*/











app.c     ALP, p. 44-46


#include "test.h"

int main ()
{
return f ();
}
/*
gcc -c test.c
gcc -c app.c
ar cr libtest.a test.o

gcc -L. -ltest app.o -o app
/usr/bin/ld: app.o: in function `main':
app.c:(.text+0xe): undefined reference to `f'
collect2: error: ld returned 1 exit status

gcc -static app.o -L. -ltest -o app
./app
echo $?
3

gcc app.o -L. -ltest -o app // use shared library
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
echo $LD_LIBRARY_PATH
:.
./app
echo $?
3

gcc app.o -L. -ltest -Wl,-rpath,. -o app
./app
echo $?
3

ldd app
libtest.so...
libc...

rm *.o // clean
*/









Chapter_2     readfile BACK_TO_TOP tiff



Comments

Popular posts from this blog

Contents