Operating System - HP-UX
1834794 Members
2998 Online
110070 Solutions
New Discussion

Re: How I put ld and ln in make file for build a shared lib in C?

 
Ai Jun Zhang
Occasional Contributor

How I put ld and ln in make file for build a shared lib in C?

Hi!

I am now writing a makefile for building a shared lib in C. After the lib compiled using cc, then I need to do ld and ln.

I do not know how to put ld and ln in a make file.

Can you please tell me how?

Thanks.
Aijun.
1 REPLY 1
RikTytgat
Honored Contributor

Re: How I put ld and ln in make file for build a shared lib in C?

Hi Aijun,

This is not so very difficult, you just have to specify the right flags.

Let's see:

Add a rule like this to your makefile

------
sl.c :
${CC} -c $< -o $*.o ${SHLIBCFLAGS} ;
${LD} $*.o -o $@ -b
------

Make sure the macro SHLIBCFLAGS is correctly defined. In my case, it is

SHLIBCFLAGS = ${CFLAGS} +z

This should be OK.

One more thing: in the newly defined rule, the whitespace before the ${CC} and the ${LD} command must be a . Do not forget this. It is a common error to use spaces there, but that will not work.

When you put all this in your Makefile and type
make libmylib.sl
the necessary commands to build your library will be executed.

Bye,
Rik