Thread: Makefile compilation

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    38

    Cool Makefile compilation

    Hey all ~~
    I'm working on a project which involves the use of a Makefile and my own static library for compilation.

    I had no problems running my project, including the Makefile, on a different computer.

    On my personal computer, I was not able to compile as I was getting an error that my .h header file for my library was not a directory. I have since put it in a folder and have solved this problem. I am now able to make this without any errors or warnings showing.

    I am however still having trouble running the whole project.. I am getting an "undefined reference" message for all the library functions I call, when i try the command "make".

    I am far from completing the project, but with an increasing number of library functions that I am callling - I really would like to get the Makefile working!

    Would be grateful for tips or pointers to get me on the track!

    Here is the link to the project! GitHub - reidantonia/ft_printf

    make -C libft/ fclean && make -C libft/
    make[1]: Entering directory '/home/ubuntu-mate/Desktop/42/ft_printfgithub/libft'
    /bin/rm -f ft_memset.o ft_strlcat.o ft_bzero.o ft_memcpy.o ft_memccpy.o ft_memmove.o ft_memchr.o ft_memcmp.o ft_strlen.o ft_strdup.o ft_strcpy.o ft_strncpy.o ft_strcat.o ft_strncat.o ft_strchr.o ft_strrchr.o ft_strstr.o ft_strnstr.o ft_strcmp.o ft_strncmp.o ft_atoi.o ft_isalpha.o ft_isdigit.o ft_isalnum.o ft_isascii.o ft_isprint.o ft_toupper.o ft_tolower.o ft_memalloc.o ft_memdel.o ft_strnew.o ft_strdel.o ft_strclr.o ft_striter.o ft_striteri.o ft_strmap.o ft_strmapi.o ft_strequ.o ft_strnequ.o ft_strsub.o ft_strjoin.o ft_strtrim.o ft_strsplit.o ft_itoa.o ft_putchar.o ft_putstr.o ft_putendl.o ft_putnbr.o ft_putchar_fd.o ft_putstr_fd.o ft_putendl_fd.o ft_putnbr_fd.o ft_lstnew.o ft_lstdelone.o ft_lstdel.o ft_lstadd.o ft_lstiter.o ft_lstmap.o ft_strupcase.o ft_strlowcase.o ft_str_is_numeric.o ft_str_is_printable.o ft_str_is_uppercase.o
    /bin/rm -f libft.a
    make[1]: Leaving directory '/home/ubuntu-mate/Desktop/42/ft_printfgithub/libft'
    make[1]: Entering directory '/home/ubuntu-mate/Desktop/42/ft_printfgithub/libft'
    gcc -Wall -Werror -Wextra -c ft_memset.c ft_strlcat.c ft_bzero.c ft_memcpy.c ft_memccpy.c ft_memmove.c ft_memchr.c ft_memcmp.c ft_strlen.c ft_strdup.c ft_strcpy.c ft_strncpy.c ft_strcat.c ft_strncat.c ft_strchr.c ft_strrchr.c ft_strstr.c ft_strnstr.c ft_strcmp.c ft_strncmp.c ft_atoi.c ft_isalpha.c ft_isdigit.c ft_isalnum.c ft_isascii.c ft_isprint.c ft_toupper.c ft_tolower.c ft_memalloc.c ft_memdel.c ft_strnew.c ft_strdel.c ft_strclr.c ft_striter.c ft_striteri.c ft_strmap.c ft_strmapi.c ft_strequ.c ft_strnequ.c ft_strsub.c ft_strjoin.c ft_strtrim.c ft_strsplit.c ft_itoa.c ft_putchar.c ft_putstr.c ft_putendl.c ft_putnbr.c ft_putchar_fd.c ft_putstr_fd.c ft_putendl_fd.c ft_putnbr_fd.c ft_lstnew.c ft_lstdelone.c ft_lstdel.c ft_lstadd.c ft_lstiter.c ft_lstmap.c ft_strupcase.c ft_strlowcase.c ft_str_is_numeric.c ft_str_is_printable.c ft_str_is_uppercase.c -I include
    ar rc libft.a ft_memset.o ft_strlcat.o ft_bzero.o ft_memcpy.o ft_memccpy.o ft_memmove.o ft_memchr.o ft_memcmp.o ft_strlen.o ft_strdup.o ft_strcpy.o ft_strncpy.o ft_strcat.o ft_strncat.o ft_strchr.o ft_strrchr.o ft_strstr.o ft_strnstr.o ft_strcmp.o ft_strncmp.o ft_atoi.o ft_isalpha.o ft_isdigit.o ft_isalnum.o ft_isascii.o ft_isprint.o ft_toupper.o ft_tolower.o ft_memalloc.o ft_memdel.o ft_strnew.o ft_strdel.o ft_strclr.o ft_striter.o ft_striteri.o ft_strmap.o ft_strmapi.o ft_strequ.o ft_strnequ.o ft_strsub.o ft_strjoin.o ft_strtrim.o ft_strsplit.o ft_itoa.o ft_putchar.o ft_putstr.o ft_putendl.o ft_putnbr.o ft_putchar_fd.o ft_putstr_fd.o ft_putendl_fd.o ft_putnbr_fd.o ft_lstnew.o ft_lstdelone.o ft_lstdel.o ft_lstadd.o ft_lstiter.o ft_lstmap.o ft_strupcase.o ft_strlowcase.o ft_str_is_numeric.o ft_str_is_printable.o ft_str_is_uppercase.o
    ranlib libft.a
    make[1]: Leaving directory '/home/ubuntu-mate/Desktop/42/ft_printfgithub/libft'
    gcc -Llibft -lft sources/ft_printf.o sources/main.o -o libftprintf.a
    sources/ft_printf.o: In function `ft_process':
    ft_printf.c.text+0xd7): undefined reference to `ft_isdigit'
    ft_printf.c.text+0x127): undefined reference to `ft_isdigit'
    ft_printf.c.text+0x156): undefined reference to `ft_strsub'
    ft_printf.c.text+0x15e): undefined reference to `ft_atoi'
    sources/ft_printf.o: In function `ft_print_arg':
    ft_printf.c.text+0x1cc): undefined reference to `ft_putstr'
    sources/ft_printf.o: In function `ft_printf':
    ft_printf.c.text+0x28e): undefined reference to `ft_strdup'
    ft_printf.c.text+0x30d): undefined reference to `ft_strnew'
    ft_printf.c.text+0x366): undefined reference to `ft_putchar'
    ft_printf.c.text+0x403): undefined reference to `ft_strlen'
    ft_printf.c.text+0x41d): undefined reference to `ft_strsub'
    collect2: error: ld returned 1 exit status
    Makefile:39: recipe for target 'libftprintf.a' failed
    make: *** [libftprintf.a] Error 1
    Cheers
    Last edited by Tigertan; 02-17-2018 at 06:02 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > -Llibft -lft
    The library paths are usually ok to write anywhere before -l, but actual libraries should appear after object files that refer to them.

    Some linkers rescan libraries, others do not.

    It seems yours scans left to right only once.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Aug 2012
    Posts
    38
    Quote Originally Posted by Salem View Post
    > -Llibft -lft
    The library paths are usually ok to write anywhere before -l, but actual libraries should appear after object files that refer to them.

    Some linkers rescan libraries, others do not.

    It seems yours scans left to right only once.
    Got it working! Cheers Salem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why JIT compilation and not full compilation?
    By C_ntua in forum General Discussions
    Replies: 8
    Last Post: 01-10-2013, 02:33 AM
  2. makefile and windows compilation
    By inkare in forum C Programming
    Replies: 33
    Last Post: 07-18-2008, 06:55 PM
  3. Pro*C Compilation.
    By asif_oracle in forum C Programming
    Replies: 4
    Last Post: 04-01-2008, 09:41 AM
  4. Conditional compilation for object files in Makefile?
    By jutirain in forum C++ Programming
    Replies: 13
    Last Post: 12-19-2007, 06:23 AM
  5. difference makefile makefile.am makefile.in
    By Bargi in forum Linux Programming
    Replies: 7
    Last Post: 10-28-2007, 02:08 PM

Tags for this Thread