Files:
/* File: testMain.c */
#include "test.h"
int main(int argc, char *argv[]) {
return test_f();
}
/* File: test.h */
extern
int test_f();
/* File: test.c */
#include "test.h"
#include "test1.h"
#include
int test_f() {
int result;
printf("test_f 1\n");
result = test1_f();
printf("test_f 2\n");
return result;
}
/* File: test1.h */
extern
int test1_f();
/* File: test1.c */
#include "test1.h"
#include
int test1_f() {
printf("test1_f\n");
return 99;
}
-- Static linking:
cc -g -c -o test1.o test1.c
cc -g -c -o test.o test.c
cc -g -o testMain testMain.c test.o test1.o
testMain
-- Dynamic linking (shared libraries):
cc -g -KPIC -G -o libtest1.so test1.c
cc -g -KPIC -G -o libtest.so test.c
cc -o testMain testMain.c -L . -l test -l test1
testMain
-- Dynamic linking of shared libraries with path information for dynamic linker:
cc -g -KPIC -G -o libtest1.so test1.c
cc -g -KPIC -G -o libtest.so test.c -L \
${TYCOON_ROOT}/src/testDir -ltest1
cd ${TYCOON_ROOT}/src
tycoon -restart
let f = bind(:Fun() :Int
"${TYCOON_ROOT}/src/testDir/libtest.so" "test_f"
"i");
f();
-- Dynamic linking of shared libraries with one master library:
cc -g -KPIC -G -o libtest1.so test1.c
cc -g -KPIC -G -o libtest.so test.c
ld -G -o libtestall.so libtest.so libtest1.so
cd ${TYCOON_ROOT}/src
tycoon -restart
let f = bind(:Fun() :Int
"${TYCOON_ROOT}/src/testDir/libtestall.so" "test_f"
"i");
f();