0
gcc -Wall -Werror -Wextra -Llibft -lft -Ilibft/include main.c

When I use the command above, the linker throws the following error message:

/tmp/ccwCUgov.o: In function `main':
main.c:(.text+0xc): undefined reference to `ft_putendl'
collect2: error: ld returned 1 exit status

I have to mention that the library libft.a in use does exist in the libft/ directory.

I'm coding on Ubuntu 18.04LTS right now(2019), but I have never encountered such problem on macOS.

The code in main.c:

#include "libft.h"

int main()
{
    ft_putendl("Hello world!");
    return (0);
}
S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
Glitch
  • 155
  • 1
  • 9

1 Answers1

0

Put -lft last in your linking command, like this:

gcc -Wall -Werror -Wextra -Llibft -Ilibft/include main.c -lft

This causes libft to be linked last, which should cause the needed functions to be included (the linker only includes objects that are needed, and at the time of processing libft.a, the objects aren't needed yet).

This probably works on Mac either because Mac includes all objects from the archive or because it links libraries last.

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76