1

I'm trying to compile a main.c file using a library called libft_malloc.so that I've already created and put it in the same directory as the file, but it generates an error saying library not found.

Compilation goes like this:

$> gcc main.c -L. -lft_malloc.so -Iinclude
ld: library not found for -lft_malloc.so
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I'm using an macOS.

Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
Glitch
  • 155
  • 1
  • 9
  • 1
    This may help: https://stackoverflow.com/a/26713370/898348 – Jabberwocky Nov 30 '21 at 16:45
  • 1
    Use `-lft_malloc`. No "`.so`" in the command-line option. Alternatively, drop the `-L` and `-l` options altogether, and replace them with a path to the library file (`./libft_malloc.so`). – John Bollinger Nov 30 '21 at 16:47
  • 2
    Do note, however, that it may be an issue to link against an uninstalled shared library, because the program will need to find it at runtime, too. There are ways to provide for that, but it does not look like you are using any of them. – John Bollinger Nov 30 '21 at 16:51
  • Yeah true, I have them both in the same directory. – Glitch Nov 30 '21 at 16:53
  • 1
    I just love that macOS has `gcc` which is just an alias for `clang` :') – Marco Bonelli Nov 30 '21 at 17:16

0 Answers0