next next up down toc Memos schedule allInOne PDF PDF mail
all, section 3.14.

3.14.  Example

main.c:
 1      #include <stdio.h>
 2      #include <math.h>
 3      
 4      int main() {
 5          printf("calling sin....\n");
 6          printf("result = %g\n", sin(1.0) );
 7          return 0;
 8      }

Source Code: Src/4/main.c

my_math.c:
 1      #include <stdio.h>
 2      #include <math.h>
 3      
 4      double sin(double x)    {
 5              printf("\t local sin ----> x = %g\n", x);
 6              return 0.0;
 7      }
 8      

Source Code: Src/4/my_math.c

math_not_nice.c:
 1      #include <stdio.h>
 2      #include <math.h>
 3      
 4      double sin(double x)    {
 5              printf("\tSay Bye Bye to your files");
 6              return 0.0;
 7      }
 8      

Source Code: Src/4/math_not_nice.c

run:
 1      set -x
 2      gcc -fpic -c my_math.c 
 3      gcc -shared -o libm.so.3 my_math.o
 4      LD_LIBRARY_PATH=/home/fac/hpb/Lectures/20102/S_T/Notes/Src/4:$LD_LIBRARY_PATH
 5      export LD_LIBRARY_PATH
 6      gcc main.c libm.so.3 -lm
 7      ldd ./a.out
 8      ./a.out 
 9      
10      gcc -fpic -c math_not_nice.c 
11      gcc -shared -o libm.so.3 math_not_nice.o
12      cp libm.so.3 ./a.out /tmp
13      LD_LIBRARY_PATH=/tmp:$LD_LIBRARY_PATH
14      cd /tmp
15      ldd ./a.out
16      ./a.out

Source Code: Src/4/run

Result:
+ gcc -fpic -c my_math.c 
+ gcc -shared -o libm.so.3 my_math.o 
LD_LIBRARY_PATH=/home/fac/hpb/Lectures/20112/S_T/Notes/Src/4:/usr/local/gnu/lib:/usr/local/X11/lib:/usr/dt/lib:/usr/openwin/lib:/usr/local/lib:/opt/SUNWspro/lib
+ export LD_LIBRARY_PATH 
+ gcc main.c libm.so.3 -lm 
+ ldd ./a.out 
        libm.so.3 =>     /home/fac/hpb/Lectures/20112/S_T/Notes/Src/4/libm.so.3
        libm.so.2 =>     /lib/libm.so.2
        libc.so.1 =>     /lib/libc.so.1
        libgcc_s.so.1 =>         /usr/local/gnu/lib/libgcc_s.so.1
        /platform/SUNW,A70/lib/libc_psr.so.1
+ ./a.out 
calling sin....
         local sin ----> x = 1
result = 0
+ gcc -fpic -c math_not_nice.c 
+ gcc -shared -o libm.so.3 math_not_nice.o 
+ cp libm.so.3 ./a.out /tmp 
LD_LIBRARY_PATH=/tmp:/home/fac/hpb/Lectures/20112/S_T/Notes/Src/4:/usr/local/gnu/lib:/usr/local/X11/lib:/usr/dt/lib:/usr/openwin/lib:/usr/local/lib:/opt/SUNWspro/lib
+ cd /tmp 
+ ldd ./a.out 
        libm.so.3 =>     /tmp/libm.so.3
        libm.so.2 =>     /lib/libm.so.2
        libc.so.1 =>     /lib/libc.so.1
        libgcc_s.so.1 =>         /usr/local/gnu/lib/libgcc_s.so.1
        /platform/SUNW,A70/lib/libc_psr.so.1
+ ./a.out 
calling sin....
        Say Bye Bye to your filesresult = 0


back next up down toc Memos schedule allInOne pdf PDF mail

Created by unroff, java2html & & hp-tools. © by hpb. All Rights Reserved (2012).
It is not allowed to print these pages on a CAST printer.
Last modified: 22/February/12 (13:17)