Objective to hide the source code provided only to. A and. h files
/*
Aston.c
*/
#include <stdio.h>
void func1 (void)
{
printf ("Func1 in aston.c\n");
}
int func2 (int a,int b)
{
printf ("Func2 in aston.c\n");
return a+b;
}
Aston.h
void func1 (void);
int func2 (int a,int b);
Makefile
All
GCC Aston.c-o aston.o-c
AR-RC Libaston.a ASTON.O
Text.c
#include "Aston.h"
#include <stdio.h>
int main (void)
{
Func1 ();
int a = FUNC2 (4,5);
printf ("A =%d.\n", a);
}
One
[email protected]: ~/ccc/hello/4.6.11.archiveuse$ Make
GCC Aston.c-o aston.o-c
AR-RC Libaston.a ASTON.O
Two
[email protected]: ~/ccc/hello/4.6.11.archiveuse$ gcc Test.c-o test
/tmp/ccsez3m1.o:in function ' main ':
TEST.C: (. text+0xa): Undefined reference to ' func1 '
TEST.C: (. text+0x1e): Undefined reference to ' Func2 '
Collect2:error:ld returned 1 exit status
Three
[email protected]: ~/ccc/hello/4.6.11.archiveuse$ gcc Test.c-o Test-laston
/usr/bin/ld:cannot Find-laston
Collect2:error:ld returned 1 exit status
Four
[email protected]: ~/ccc/hello/4.6.11.archiveuse$ gcc Test.c-o Test-laston-L._l. To link the current directory
[email protected]: ~/ccc/hello/4.6.11.archiveuse$ ls
ASTON.C aston.h aston.o libaston.a Makefile test test.c
Five
[email protected]: ~/ccc/hello/4.6.11.archiveuse$./test
Func1 in ASTON.C
Func2 in ASTON.C
A = 9.
Make a static link library yourself and use