0

I'm trying to compile libft.a and main.c with this command:

gcc -Wall -Werror -Wextra -I./inc/ -L./inc/ -lft main.c

and this is what I get:

/tmp/ccuwcCPB.o: in function « main »:
main.c:(.text+0x1b): undefined reference to « ft_putchar »
collect2: error: ld returned 1 exit status

I have tried to remove my header file and I get another error about implicit declaration, so this is not a header problem.

I have tried to use a different libft.a coming from an other student (same work) but same problem again.

Does someone have an idea about this error?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Nestoyeur
  • 29
  • 3
  • 3
    Libraries, especially static libraries, should be listed after source files or object files on the linking command line. And what's your library doing in the `inc` directory? Libraries go in a `lib` directory — hence `/usr/lib` and `/lib` and `/usr/local/lib`. Anyway, hacking the compiler line: `gcc -Wall -Werror -Wextra -I./inc -L./inc main.c -lft` (assuming you really have `libft.a` in your `inc` directory). – Jonathan Leffler Nov 25 '15 at 23:45
  • Incidentally, it's good to see you taking warnings seriously; take kudos for that. – Jonathan Leffler Nov 25 '15 at 23:51
  • See also [Undefined reference to `pthread_create()`](https://stackoverflow.com/questions/9253200) and [Trouble compiling against static library](https://stackoverflow.com/questions/22623851). – Jonathan Leffler Nov 25 '15 at 23:55
  • Awsome it work well now, thanks :) for this inc/libft.a it was for test how work the options -L and -l with gcc but yeah when i will finish this lib it will go in all my other project in a lib folder ;p – Nestoyeur Nov 26 '15 at 00:17

0 Answers0