[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: how to link special libraries while cross compiling



> -----Original Message-----
> From: Latha [mailto:ranga_axis@xxxxxxx.in] 
> Sent: Saturday, December 14, 2002 00:10
> To: dev-etrax@xxxxxxx.com
> Subject: how to link special libraries while cross compiling
> 
> hi all,
> 
> I am using some graphics libraries in my C code. How
> to link these libraries while cross compiling for Axis
> Developer board.
> 
> what are changes to be made for Makefile, which is
> provided with example program (helloworld!)

Assuming that you have a library called libmylibrary.so
that is built for CRIS and is installed in $(prefix)/lib
(see the example Makefile below for how to build a library),
then all you should need to do is add 'LDLIBS += -lmylibrary' 
to the Makefile below. 

If you have installed the library somewhere else, then you
may need to add a line like 'LDFLAGS += -L$(prefix)/some/dir'. 

Also if you have header files that are needed to interface
to the library, then you may need to add a line like 
'CFLAGS += -I$(prefix)/include/mylibrary'.

> ******************************************************
> AXIS_USABLE_LIBS = GLIBC UCLIBC
> include $(APPS)/Rules.elinux
> 
> PROGS     = hello
> 
> INSTDIR   = $(prefix)/bin/
> INSTMODE  = 0755
> INSTOWNER = root
> INSTGROUP = root
> 
> OBJS = hello.o

CFLAGS   += -I$(prefix)/include/mylibrary
LDFLAGS  += -L$(prefix)/lib
LDLIBS   += -lmylibrary

> all: $(PROGS)
> 
> $(PROGS): $(OBJS)
> 	$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
> 
> install:	$(PROGS)
> 	$(INSTALL) -d $(INSTDIR)
> 	$(INSTALL) -m $(INSTMODE) -o $(INSTOWNER) -g
> $(INSTGROUP) $(PROGS) $(INSTDIR)
> 
> clean:
> 	rm -f $(PROGS) *.o core
> 
> *****************************************************
> 
> thanks in advance
> 
> 
> Regards
> Ranganadh

This is an example Makefile for building a library.
All you should need to change is the $(NAME) variable
which should be the name of the library, $(SRCS) which
should be a list of all the source files, and $(HDRS)
which should be a list of any header files that are
needed to use the library (i.e., the API).

*****************************************************

AXIS_USABLE_LIBS = UCLIBC GLIBC
include $(AXIS_TOP_DIR)/tools/build/Rules.axis

NAME      = mylibrary

INCDIR    = $(prefix)/include/$(NAME)
LIBDIR    = $(prefix)/lib

# The name of the main library target.
ifeq ($(AXIS_SHARE_LIBS),yes)
LIBRARY_NAME = lib$(NAME).so
CFLAGS += -fpic
PERM = -m 0755
else
LIBRARY_NAME = lib$(NAME).a
PERM = -m 0644
endif

# The C code source files for this library.
SRCS      = mysource1.c mysource2.c mysource3.c

# The header files for this library.
HDRS      = myheader1.h myheader2.h

OBJS      = $(SRCS:.c=.o)

CFLAGS   += -MMD -I../include

##########################################################################

all:	$(LIBRARY_NAME)

lib$(NAME).a:	$(OBJS)
	@rm -f $@
	$(AR) ucvr $@ $^
	$(RANLIB) $@

lib$(NAME).so:	$(OBJS)
	@rm -f $@
	$(CC) -shared -o $@ $^

install:	all
	$(INSTALL) -d $(INCDIR) $(LIBDIR)
	$(INSTALL) $(HDRS) $(INCDIR)
	$(INSTALL) $(PERM) $(LIBRARY_NAME) $(LIBDIR)

uninstall:
	rm -f $(LIBDIR)/$(LIBRARY_NAME)

clean:
	rm -f *.o *.a *.so *.d *~

-include *.d

*****************************************************

//Peter