Hello folks.
I have my own mini C library with a short but growing number of functions. Some time ago I added printf to the collection, or rather created a printf implementation that was compiled into it's own static library.
I never actually added it to my C library until now. I had absolutely no idea how best to do this, specially since I was using many of my library functions -statically linked- in my printf.
At the end this is what I went with:
Code:
CC = gcc
CFLAGS = -Wall -Wextra -Werror
OPTFLAGS = -O3
NAME = libft.a
SRC = ft_abs.c ft_bzero.c ft_chrcount.c ft_getsignificantdigits.c ft_isalpha.c ft_isdigit.c \
ft_isprint.c ft_memalloc.c ft_memcpy.c ft_memmove.c ft_memset.c ft_pow.c ft_realloc.c \
ft_strcat.c ft_strchr.c ft_strclr.c ft_strcpy.c ft_strinsert.c ft_strlen.c ft_strncat.c \
ft_strappend.c ft_strnew.c ft_strrev.c ft_tolower.c ft_toupper.c ft_itoa.c ft_lltoa.c \
ft_ulltoa.c ft_strcpynew.c ft_stpcpy.c ft_strcpycnt.c ft_getfile.c ft_strsplit.c \
ft_strsplit_words.c ft_getdelim.c ft_getstdin.c
PRINTFSRC = ft_printf.c ft_printf_types.c common.c extract.c insert.c parse.c \
pf_floattobinary.c pf_ftoa.c pf_ldtoa.c pf_lltoa.c pf_ulltoa.c round.c \
pf_ultobinary.c fp_operations.c hex_common.c infinity.c double_conversions.c \
hex_conversions.c longdouble_conversions.c ld_hex_conversions.c time.c \
base_conversions.c int_conversions.c string_conversions.c errno.c redirection.c \
color.c format.c nonprint.c default.c
HEADERS = ft_printf.h arguments.h common.h fp_common.h infinity.h color.h libft.h \
unicode.h ft_errno.h nonprint.h
INCLUDES = -iquote ./include -iquote ./src/ft_printf
OBJECTS=$(SRC:%.c=%.o)
PRINTF_OBJECTS=$(PRINTFSRC:%.c=%.o)
.PHONY: all clean fclean re
VPATH = src src/ft_printf/src src/ft_printf/src/arguments src/ft_printf/src/conversions \
src/ft_printf/src/conversions/common src/ft_printf/src/conversions/floating_point \
src/ft_printf/src/extras src/ft_printf/src/formatting \
all: $(NAME)
$(NAME): $(OBJECTS) $(PRINTF_OBJECTS)
ar -rcs $(NAME) $^
$(OBJECTS): $(SRC) $(PRINTFSRC)
$(CC) $(CFLAGS) $(OPTFLAGS) -c $(INCLUDES) $^
clean:
rm -f $(OBJECTS)
rm -f $(PRINTF_OBJECTS)
fclean: clean
rm -f $(NAME)
re: fclean all
I smashed everything together...
Problem is, in my current project -which is using this library- I have a function with the same name as an external function I use in my printf, parse_input. When I call printf from within my program, and control reaches the point where it should call printf's own parse_input, it calls my program's parse_input instead, eventually resulting in a EXC_I386_GPFLT error.
Now, the obvious solution would be to simply rename the function to avoid the issue, but I get the feeling I am doing something fundamentally wrong here in the manner I'm integrating printf into my library, which results in me having these sort of problems.
At risk of abusing your patience, I ask if you could give me a few pointers on the proper way to do this.
Thank you.