Rcjp's Weblog

June 2, 2006

Using an archive library

Filed under: c, unix — rcjp @ 1:19 pm

main program that calls into the archive test1.c

#include <stdio.h>

int main()
{
    printf("inside main program\n");
    mytest();
    printf("back inside main program\n");
}

the code in the archive mylib1.c

#include <stdio.h>

int mytest()
{
    printf("inside c lib !!!\n");
    return 2;
}

build with the script

#!/bin/sh
cc -c mylib1.c
ar -cvq mylib1.a mylib1.o
#
# create a symbol table to link with
# 
ranlib mylib1.a
# 
# now use the lib
#
cc test1.c mylib1.a -o test1

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: