0

I have a c program with a makefile that works perfectly on macos but when i try yo run it on linux it gives me a bunch of errors

gcc ./libft/libft.a srcs/main.o -o push_swap
/usr/bin/ld: srcs/main.o: in function `sa':
main.c:(.text+0x97): undefined reference to `ft_putstr'
/usr/bin/ld: srcs/main.o: in function `sb':
main.c:(.text+0x149): undefined reference to `ft_putstr'
/usr/bin/ld: srcs/main.o: in function `ss':
main.c:(.text+0x1eb): undefined reference to `ft_putstr'
/usr/bin/ld: srcs/main.o: in function `pa':
main.c:(.text+0x236): undefined reference to `ft_putstr'
/usr/bin/ld: srcs/main.o: in function `pb':
main.c:(.text+0x2df): undefined reference to `ft_putstr'
/usr/bin/ld: main.c:(.text+0x327): undefined reference to `ft_putnbr_fd'
/usr/bin/ld: srcs/main.o: in function `printstack':
main.c:(.text+0x3b3): undefined reference to `ft_putnbr_fd'
/usr/bin/ld: main.c:(.text+0x3bd): undefined reference to `ft_putchar'
/usr/bin/ld: main.c:(.text+0x3df): undefined reference to `ft_putnbr_fd'
/usr/bin/ld: main.c:(.text+0x3e9): undefined reference to `ft_putchar'
/usr/bin/ld: main.c:(.text+0x404): undefined reference to `ft_putstr'
/usr/bin/ld: main.c:(.text+0x413): undefined reference to `ft_putstr'
/usr/bin/ld: srcs/main.o: in function `main':
main.c:(.text+0x4a9): undefined reference to `ft_atoi'
collect2: error: ld returned 1 exit status
make: *** [Makefile:23: push_swap] Error 1

I believe the cause is the Makefile because it can't find the function that the makefile is suppose to compile too but im not sure about that. Anyways here is my makefile:

NAME = push_swap
LIBFT_PATH = libft
LIBFT = libft.a

SRC_FILES = main.c 
SRC_DIR = srcs/
SRC = ${addprefix ${SRC_DIR}, ${SRC_FILES}}
OBJ = ${SRC:.c=.o}

CC = gcc
CFLAGS = -Wall -Wextra -Werror -pg -g
AR = ar -rcs

%.o: %.c
    ${CC} -c -Imlx -c $< -o $@

all: ${NAME}

libft:
    @MAKE -sC ${LIBFT_PATH}

${NAME}: libft ${OBJ}
    ${CC} ${LIBFT_PATH}/${LIBFT} ${OBJ} -o ${NAME}

clean:
    rm -f ${OBJ}
    ${MAKE} -C ${LIBFT_PATH} clean

fclean: clean
    rm -f ${NAME}
    ${MAKE} -C ${LIBFT_PATH} fclean

re: fclean all

.PHONY: all clean flcean re
yazukii
  • 29
  • 4
  • 3
    Try moving `./libft/libft.a` to the end of the link command. – G.M. Jan 11 '23 at 13:37
  • @G.M. Thank you it worked but i don't understand why tho. – yazukii Jan 11 '23 at 14:40
  • 3
    Does this answer your question? [Why does the order in which libraries are linked sometimes cause errors in GCC?](https://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc) – G.M. Jan 11 '23 at 14:44
  • aaaa libft. Good times. Goodluck! Its a hell of a time. Enjoy it! – testfile Jan 13 '23 at 07:53

0 Answers0