-1

I have two .so libraries named: libSDL_ttf.so and libSDL_image.so.

In the gcc command inside the makefile I added: -llibSDL_image.so -llibSDL_ttf.so but I get the error:

/usr/bin/ld: cannot find -llibSDL_image.so  
/usr/bin/ld: cannot find -llibSDL_ttf.so  
collect2: error: ld returned 1 exit status  

I've understood that the lib prefix is a convention so I also tried to omit it like this: -lSDL_image.so -lSDL_ttf.so but it didn't help too.

those libraries live next to the makefile so I don't think I should add a -L argument, nevertheless, I've tried to add the following just to make sure: -L$(shell pwd),but again got this error.

Why is that? How to fix?

Community
  • 1
  • 1
hibye
  • 57
  • 6
  • 2
    try `-L. -lSDL_image -lSDL_ttf` – markgz Oct 01 '15 at 22:16
  • I tried this (without the dot): `-L -lSDL_image -lSDL_ttf` and now it screams only about the TTF library. Why? – hibye Oct 01 '15 at 22:37
  • The dot gives a syntax error. – hibye Oct 01 '15 at 22:50
  • the '.' is telling the linker to look in the current directory for the two libraries. If the '.' does not work, you could try `-L./` which has the same effect – user3629249 Oct 01 '15 at 22:54
  • Doesn't work either: /usr/bin/ld:.//libSDL_image.so: file format not recognized; treating as linker script /usr/bin/ld:.//libSDL_image.so:1: syntax error collect2: error: ld returned 1 exit status make: *** [all] Error 1 – hibye Oct 01 '15 at 22:58
  • When I change it to: `-L -lSDL_ttf -lSDL_image` (without the dot) it screams about the image-library only. – hibye Oct 01 '15 at 22:59
  • Where you originally had `-llibSDL_image.so -llibSDL_ttf.so`, you need `-lDSL_image -lSDL_ttf`. You omit the `lib` prefix and the `.so` suffix when you use the `-l` option to specify the library name. You may, or may not, also need to specify the directory where the SDL libraries are found. If they're in the current directory, then use `-L .` (normally one or two arguments is OK; in case of doubt, use two). If they're somewhere else, then specify `-L /some/where/else` instead. – Jonathan Leffler Oct 01 '15 at 23:03

2 Answers2

0

You need -L to specify the LIBRARY_PATH , and -l to specify the library files.

CiceroDev
  • 31
  • 2
0

When adding a library you should remove its prefix and extension.

In this case libABC.so would be used like as -lABC

DMH
  • 182
  • 1
  • 2
  • 17
  • I tried this: `-L -lSDL_image -lSDL_ttf` but for some reason it screams only about the TTF library. – hibye Oct 01 '15 at 22:37
  • does the libSDL_ttf.so library actually exist? – user3629249 Oct 01 '15 at 23:00
  • Without a `.` argument for the `-L`, it thinks that `-lSDL_image` is the path to a directory (which it can't find, but that doesn't matter). – Jonathan Leffler Oct 01 '15 at 23:00
  • do you have header files for those two libraries? are you #include'ing those header files using #include "SDL_image.h" Be sure to use " " and not < > (assuming that SDL_image.h were the name of the one of the header files)? When compiling with all warnings enabled, does the compiler raise any warning/error messages? – user3629249 Oct 01 '15 at 23:06
  • when linking, the library references must be last on the line, otherwise the object code will not be linked yet, resulting the linker, when it sees the library references has not yet generated any unresolved external references, so will not look in the libraries – user3629249 Oct 01 '15 at 23:10
  • @JonathanLeffler, I am confused since the dot argument generate a syntax error. – hibye Oct 01 '15 at 23:24
  • @hibye: I'm confused about that too, but you've not shown a complete command line, so it is hard to know what you're doing, let alone what you're doing wrong. Maybe you should show the complete command line you're using, and the exact error message you get when you include `-L.` or `-L .`. (Is it the same? It should be!) And maybe you should identify which directory holds the `libSDL_*.so` libraries — is it the current directory (if so, why?), or some system directory (which one?) or some non-standard location. Rest assured that GCC on Linux does normally manage to link shared libraries. – Jonathan Leffler Oct 01 '15 at 23:31
  • @hibye: Also, you mention 'syntax error' — is that really what it says? If so, it is highly odd. Neither `-L.` nor `-L .` is a syntax error under any normal circumstances, so you need to identify what is saying 'syntax error'. – Jonathan Leffler Oct 01 '15 at 23:34
  • Could you look at this link? https://www.libsdl.org/projects/SDL_image/release-1.2.html – hibye Oct 02 '15 at 00:02
  • should I choose devel or the other binary? – hibye Oct 02 '15 at 00:02