Reputation:
I'm doing a network C library and I want to support also SCTP. I have in this file wrapper_socket_functions.c
/*SCTP WRAPPER */
void
Sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, int flags)
{
int rbindx = sctp_bindx(sd, addrs, addrcnt, flags);
if(rbindx == -1)
prog_error("Sctp_bindx error",true,errno);
}
void
Sctp_connectx(int sd, struct sockaddr *addrs, int addrcnt, sctp_assoc_t *id)
{
int rconnectx = sctp_connectx(sd, addrs, addrcnt, id);
if(rconnectx == -1)
prog_error("Sctp_connectx error",true,errno);
}
int
Sctp_peeloff(int sd, sctp_assoc_t assoc_id)
{
int rpeeloff = sctp_peeloff(sd, assoc_id);
if(rpeeloff == -1)
prog_error("Sctp_paleof error",true,errno);
return rpeeloff;
}
And i have this makefile.
CC = gcc
CFLAGS = -lsctp -c -std=gnu11 -g -Wall -o
LIB_PATH = lib/
BIN_PATH = bin/
OBJECTS_LIBRARY = bin/error.o bin/signal.o bin/io_socket.o bin/wrapper_socket_functions.o bin/wrapper_stdio.o bin/wrapper_convert.o bin/wrapper_io_socket.o bin/wrapper_unix.o bin/handlers.o bin/miscellaneous.o bin/protocol.o
CLIENT_FILES = bin/client.o
SERVER_FILES = bin/server.o
all:
#Compile MAIN_FILES
$(CC) $(CFLAGS) $(BIN_PATH)client.o client.c
$(CC) $(CFLAGS) $(BIN_PATH)server.o server.c
#Compile LIB_FILES
$(CC) $(CFLAGS) $(BIN_PATH)handlers.o $(LIB_PATH)handlers.c
$(CC) $(CFLAGS) $(BIN_PATH)signal.o $(LIB_PATH)signal.c
$(CC) $(CFLAGS) $(BIN_PATH)error.o $(LIB_PATH)error.c
$(CC) $(CFLAGS) $(BIN_PATH)wrapper_socket_functions.o $(LIB_PATH)wrapper_socket_functions.c
$(CC) $(CFLAGS) $(BIN_PATH)wrapper_stdio.o $(LIB_PATH)wrapper_stdio.c
$(CC) $(CFLAGS) $(BIN_PATH)wrapper_convert.o $(LIB_PATH)wrapper_convert.c
$(CC) $(CFLAGS) $(BIN_PATH)wrapper_io_socket.o $(LIB_PATH)wrapper_io_socket.c
$(CC) $(CFLAGS) $(BIN_PATH)io_socket.o $(LIB_PATH)io_socket.c
$(CC) $(CFLAGS) $(BIN_PATH)wrapper_unix.o $(LIB_PATH)wrapper_unix.c
$(CC) $(CFLAGS) $(BIN_PATH)miscellaneous.o $(LIB_PATH)miscellaneous.c
$(CC) $(CFLAGS) $(BIN_PATH)protocol.o $(LIB_PATH)protocol.c
#Link CLIENT
$(CC) -o $(BIN_PATH)client $(OBJECTS_LIBRARY) $(CLIENT_FILES)
#Link SERVER
$(CC) -o $(BIN_PATH)server $(OBJECTS_LIBRARY) $(SERVER_FILES)
#Remove unwanted objects
rm -rf bin/*.o
The problem is when I link them together in two different bin server and client it tells me this:
undefined reference to sctp_bindx
undefined reference to sctp_connectx
undefined reference to sctp_peeloff
Note that when I compile with -lsctp
it compiles fine but, when I try to link that *.o file it complains like above. Also I have installed the lksctp_tools and checked if my kernel support it with checksctp
~ $ checksctp
Sctp supported
Upvotes: 1
Views: 1164
Reputation:
Remove the CFLAGS
arg -lsctp
and add this in LINKFLAGS = -lsctp
and when linking add after $(CC) $(LINKFLAGS).
Upvotes: 2