static/shared_lib example added
This commit is contained in:
parent
ea9e3ce17c
commit
565da568de
|
@ -0,0 +1,20 @@
|
|||
#!/bin/sh
|
||||
|
||||
CC=cc
|
||||
LIBNAME=mean
|
||||
LIBREV=1
|
||||
LIBVER=1.0.0
|
||||
TEST=main
|
||||
rm *.out *.o *.a *.0 *.1 ${TEST}_* *.so &>/dev/null
|
||||
# --- dynamic ---
|
||||
$CC -c -fPIC $LIBNAME.c -o $LIBNAME.o
|
||||
$CC -shared -Wl,-soname,lib${LIBNAME}.so.${LIBREV} -o lib${LIBNAME}.so.$LIBVER $LIBNAME.o
|
||||
ldconfig -n .
|
||||
ln -s lib${LIBNAME}.so.${LIBREV} lib${LIBNAME}.so
|
||||
$CC $TEST.c -L. -l${LIBNAME} -o ${TEST}_dynamic
|
||||
# --- static ---
|
||||
ar rcs lib${LIBNAME}.a $LIBNAME.o
|
||||
$CC $TEST.c -static -L. -l${LIBNAME} -o ${TEST}_static
|
||||
|
||||
# --- run dynamic ---
|
||||
LD_LIBRARY_PATH=. ./main_dynamic
|
|
@ -0,0 +1,15 @@
|
|||
#include <stdio.h>
|
||||
#include "mean.h"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
||||
double v1, v2, m;
|
||||
v1 = 5.2;
|
||||
v2 = 7.9;
|
||||
|
||||
m = mean(v1, v2);
|
||||
|
||||
printf("The mean of %3.2f and %3.2f is %3.2f\n", v1, v2, m);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
//#include <stdio.h>
|
||||
|
||||
double mean(double a, double b) {
|
||||
return (a+b) / 2;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
double mean(double, double);
|
Loading…
Reference in New Issue