Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
106 views
in Technique[技术] by (71.8m points)

c - How to compile a static library using makefile

I want to create a static library using Makefile in linux.

I want to know if this makefile true or not ? I'm open to other ideas. Thanks all.

NAME= libamqp.a
CC := gcc
CFLAGS := -c -Wall -g
SRCDIR := src
OBJDIR := obj
#definition des fichiers headers
INCLUDES := -I/usr/local/include/ -I/home/tvi/projets/RabbitMQ/libamqp/dlo -I/home/tvi/projets/RabbitMQ/rabbitmq-c/librabbitmq 
#definition des librairies
LFLAGS := -L/usr/local/lib64
LDFLAGS :=
LIBS := -L. -lrabbitmq
SRCS_RAW := amqp_connexion.c amqp_consommateur.c amqp_deconnexion.c amqp_producteur.c amqp_outils.c

SRCS := $(addprefix $(SRCDIR)/,$(SRCS_RAW))
OBJS := $(addprefix $(OBJDIR)/,$(SRCS_RAW:.c=.o))


.PHONY: all
all: $(NAME)
    @echo "$(MAKE) : Tout est généré"

$(NAME):$(OBJS)
    $(CC) $(CFLAGS) $(SRCS) $(INCLUDES) $(LFLAGS) $(LIBS)
    ar rcs $(NAME) $(OBJS) 
    ranlib $(NAME)


$(OBJS): $(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
    $(CC) $(CFLAGS)  -c $< -o $@ $(INCLUDES)
    
.PHONY: clean
clean:
    $(RM) *~  $(NAME)
    $(RM) -r  $(OBJDIR)
question from:https://stackoverflow.com/questions/65902124/how-to-compile-a-static-library-using-makefile

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
NAME= libamqp.a
CC := gcc
CFLAGS := -Wall -g
SRCDIR := src
OBJDIR := obj
#definition des fichiers headers
INCLUDES := -I/usr/local/include/ -I/home/tvi/projets/RabbitMQ/libamqp/dlo -I/home/tvi/projets/RabbitMQ/rabbitmq-c/librabbitmq 
#definition des librairies
LFLAGS := -L/usr/local/lib64
LDFLAGS :=
LIBS := -L. -lrabbitmq
SRCS_RAW := amqp_connexion.c amqp_consommateur.c amqp_deconnexion.c amqp_producteur.c amqp_outils.c

SRCS := $(addprefix $(SRCDIR)/,$(SRCS_RAW))
OBJS := $(addprefix $(OBJDIR)/,$(SRCS_RAW:.c=.o))

#$(info DEBUG: SRCS=$(SRCS))
#$(info DEBUG: OBJS=$(OBJS))
#$(info DEBUG: EXEC=$(EXEC))

.PHONY: all
all: $(NAME)
    @echo "$(MAKE) : Tout est genere"

$(NAME):$(OBJS)
    ar rcs $(NAME) $(OBJS) 
    ranlib $(NAME)

#règle pour créer un répertoire d'objets s'il n'existe pas
$(OBJDIR):
    mkdir $(OBJDIR)

#définir une règle implicite pour créer des objets dans leur propre répertoire
#(note - ordre uniquement la dépendance sur le répertoire d'objets)
#$< :premier_dependance $@:cible 
$(OBJS): $(OBJDIR)/%.o: $(SRCDIR)/%.c | $(OBJDIR)
    $(CC) $(CFLAGS) $(INCLUDES) -c $< -o $@ 
    
.PHONY: clean
clean:
    $(RM) *~  $(NAME)
    $(RM) -r  $(OBJDIR)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...