0

When i try to compile a program linking a library with gcc (on the recent 13.1.0), with a command like this: g++ -I/path/to/header -L/path/to/library -llibrary file.cpp

the output tell me 'cannot find -llibrary: no such file or directory'

i already deleted and reinstalled gcc and tried to change the invocation order with the same result

coder
  • 1
  • 1
  • 3
    What is the content of `/path/to/library/`? Is there any `liblibrary.a`/`.so` there? – Daniel Langr Jun 14 '23 at 14:12
  • The rules for how g++ maps the library name to a file name are varied and depend on the platform used (e.g. MinGW g++ uses different rules from linux g++). So explain what platform, what name you use and what filename you are trying to link with. I'm sure the answer is very simple but with the information given so far it impossible to say what mistake you made. – john Jun 14 '23 at 14:18

1 Answers1

1

It sounds like you're assuming that cannot find -llibrary indicates that GCC is interpreting -llibrary as the name of an input file rather than as an -l option with the value library.

But actually, that's just GCC's weird way of saying "I couldn't match library to a library". After all, it checks in a number of places for a number of differently-named files (e.g. liblibrary.a but also library.a) so it has no way of knowing which of these filenames it was supposed to find.

See this question for various reasons GCC might be unable to find the library.

Sneftel
  • 40,271
  • 12
  • 71
  • 104