I got this error when i launched make "undefined reference to this
functions" : How can i solve the problem ?
tvi-stwunt@es7-stkw-dev-workstation:/home/tvi/projets/RabbitMQ/test_amqp> make
gcc -L/home/tvi/projets/RabbitMQ/libamqp -lrabbitmq -lamqp amqp_consommateur.o -o amqp_consommateur
amqp_consommateur.o: In function main': /home/tvi/projets/RabbitMQ/test_amqp/amqp_consommateur.c:48: undefined reference to
amqp_connexion'
/home/tvi/projets/RabbitMQ/test_amqp/amqp_consommateur.c:49: undefined reference to amqp_consommateur' /home/tvi/projets/RabbitMQ/test_amqp/amqp_consommateur.c:50: undefined reference to
amqp_deconnexion'
collect2: error: ld returned 1 exit status
make: *** [amqp_consommateur] Error 1
This is my c function which contain the main
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <amqp.h>
#include <amqp_tcp_socket.h>
#include "libamqp.h"
#include "amqp_outils.h"
int main(int argc, char const *const *argv) {
amqp_connection_state_t conn;
char const *cle_liaison;
char const *echange;
char const *nom_hote;
int port;
char const *queue;
nom_hote = argv[1];
port = atoi(argv[2]);
queue = argv[3];
echange = "amq.direct"; /* argv[3]; */
cle_liaison = "test queue"; /* argv[4]; */
conn = amqp_new_connection();
amqp_connexion(conn, nom_hote, port, echange, cle_liaison, queue);
amqp_consommateur(conn, cle_liaison, echange);
amqp_deconnexion(conn);
return 0;
}
This is the Makefile
CC := gcc
CFLAGS := -Wall -Werror -g
INCLUDES := -I/usr/local/include/ -I/home/tvi/projets/RabbitMQ/libamqp/dlo
LFLAGS := -L/home/tvi/projets/RabbitMQ/libamqp
LDLIBS := -lrabbitmq
SRCS := amqp_consommateur.c amqp_producteur.c
#LIBS := -L. -lamqp
OBJS := $(SRCS:.c=.o)
PROGS := $(SRCS:.c=)
.PHONY: all
all: $(PROGS)
@echo "$(MAKE) : Tout est généré"
$(PROGS) : % : %.o Makefile
$(CC) $(LDLIBS) $(LFLAGS) $< -o $@
clean:
rm -f $(PROGS) $(OBJS)
%.o: %.c Makefile
$(CC) $(CFLAGS) $(INCLUDES) -c $<
My goal is to generate the executable for
the two files amqp_consommateur and amqp_producteur
question from:
https://stackoverflow.com/questions/65919791/undefined-reference-to-functions-called-from-the-static-library 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…