Friday, December 31, 2010

'Hello world' application in C with static library

I will show how to create 'Hello world' application in C, which will use static library.

Firstly, you must create header file for the library. In this file all functions will be declared.

extern void printhw();

Next, you must create source file and implement functions declared in the header file.


void printhw()
 printf("Hello world!\n");

Then compile your library.

gcc -c mylib.c

After compiling the library you must create an application which would use it.


int main()

 return 0;

Compile your application.

gcc -c main.c

Finally, make and run application.

gcc -o app main.o mylib.o

You must get this result:

Hello world!

No comments:

Post a Comment