Link Static Link Library in Linux

Source: Internet
Author: User

The makefile for generating static/dynamic link libraries is as follows:

#CC:=arm-linux-gcc
CFLAGS := -I..
LDFLAGS := -lpthread -lrt

SRCS := $(wildcard *.c)

ifdef ARCH
libclient := libclient-$(ARCH).a
else
libclient := libclient.a
endif

all: $(libclient) libclient.so

$(libclient): client.o net.o
$(AR) -rcv $@ $^

libclient.so: client.o net.o
$(CC) -shared -o $@ $^

.depend: Makefile $(SRCS)
@$(CC) $(CFLAGS) -MM $(SRCS) >$@
sinclude .depend

clean:
rm -rf *.o .depend $(test_client) apitest $(libclient) libclient.so

The makefile used to link the dynamic link library is as follows:

ARCH=arm-linux

ifdef ARCH
CC:=$(ARCH)-gcc
AR:=$(ARCH)-ar
export ARCH
export CC
export AR
endif

CFLAGS:=-I..
LDFLAGS:=-L. -lrt

SRCS := $(wildcard *.c)

ifdef ARCH
camera_track := camera_track-$(ARCH)
LIB:=-lclient-$(ARCH)
else
camera_track := camera_track
LIB:=-lclient
endif

all: $(camera_track)

$(camera_track): camera_track.o camera_ctrl.o
$(CC) $(LDFLAGS) -o $@ $^ $(LIB)

.depend: Makefile $(SRCS)
@$(CC) $(CFLAGS) -MM $(SRCS) >$@
sinclude .depend

clean:
rm -rf *.o .depend $(camera_track)

You can use the following command to compile the SDK directly using the command line:
Arm-Linux-gcc-L.-LRT-O camera_track camera_track.c camera_ctrl.c-lclient

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.