Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can an external library be linked to a C programm with "make"?

Status
Not open for further replies.

firelex

Programmer
Jan 10, 2002
118
DE
Hello, all!
I'm a newbie in make.
My trouble is: I have a library (in an [tt]*.a[/tt] file) and want be able to use it's functions. How can I bind this lib to my programm? I thought it goes with [tt]make[/tt] somehow. I know it should be done with [tt]-l[/tt] option of make. BUT! The Makefile isn't mine I doing the reverse programming here and it isn't funny any more.

Here is a part of the Makefile:
[tt]
include ../Makefile.inc

DEST = libcommon.a
OBJS = utils.o debug.o fault.o

GLINFOBJS = globinfo.o ../infod/infod_clnt.o ../infod/infod_xdr.o

###

.PHONY: all install clean veryclean depend

all: $(DEST) libglobinfo.a

install: all

clean:
rm -f *.o *~

veryclean: clean
rm -f libcommon.a libglobinfo.a libtcl_gdbm.a

###

$(DEST): $(OBJS)
ar r $@ $(OBJS)

libglobinfo.a: $(GLINFOBJS)
ar r $@ $(GLINFOBJS)
[/tt]
The file, where I need some functions of that external lib is globinfo.c. I don't understand at all where should I put that [tt]-l[/tt] thing? In [tt]Makefile.inc[/tt]
are given the compiler things like

[tt]
CC = gcc -pipe

INCLUDES = -I/usr/X11R6/include -I/usr/include/xyz -I../common -I../rpc

DEFINES = -D_GNU_SOURCE -D_REENTRANT
ifndef OPTIMIZE
DEFINES += -D_DEBUG
endif

CFLAGS = $(INCLUDES) $(DEFINES)

CFLAGS += -mpentium -O -g -Wall #-Wno-implicit
LDFLAGS = -g

LIBPATH = -L/usr/X11R6/lib -L../common -L../rpc
.............
[/tt]

Any ideas?
Thanks.
 

I'm no prgrammer but you would propbably need to put it in either the CFLAGS or LDFLAGS variable.

Find the line where it actually compiles (gcc -something) and look at that line to figure it out.

Cheers

Henrik Morsing
Certified AIX 4.3 Systems Administration
& p690 Technical Support
 
You need to modify the
Code:
LIBPATH
line, adding the directory where your .a files (probably statically compiled libraries) are at. That's how it's done with 'gcc'. -L <your lib paths>, -I <your include paths>.

--
JR
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top