20

I am sorry! I have googled this a lot and cannot find an answer! It's dumb I know.

I cannot link in static libraries(*.a) in eclipse cdt. I listed them all in Project->Settings-> GCC C++ linker -> Libraries. I used the absolute path to make sure I had the lib correct... and i get:

cannot find -l/usr/local/lib/libboost_date_time.a

I am sure it's stupid whatever I am doing wrong :(

Edit -- and i should mention i am linking the libraries at run time...

JonnyCplusplus
  • 881
  • 3
  • 12
  • 22
  • 1
    You can specify the full path for libs in gcc by prepending ':'. So in your case that would be '-l:/usr/local/lib/libboost_date_time.a', or add ':/usr/...' to the libraries in eclipse. But the convention of prefix 'lib' and adding search paths is there for a reason, so better use absolute paths only if _really_ necessary. – erebos Apr 14 '16 at 13:42

3 Answers3

19

I remember having a similar issue way back when I was compiling our code under linux (coming from a windows background) and if I recall correctly specifying the absolute path to the static lib also didn't work.

Are you aware that to link to "libboost_date_time.a", you need to specify "boost_date_time" without the "lib" and the ".a"? In my case that solved the problem. /usr/local/lib should be on your path in any case AFAIR.

Ralf
  • 9,405
  • 2
  • 28
  • 46
16

Static libraries or archives are just a collection of object files.

Add the archive as Other Objects under C/C++ Build -> Settings -> C++ Linker -> Miscellaneous:

enter image description here

Some folks cry bloody murder over specifying a full pathname. I find it works in practice (unlike theory at times), and its no worse than breaking the path and filename, and then specifying them with -L and -l. And did I mention it actually works in practice...

jww
  • 97,681
  • 90
  • 411
  • 885
  • I've tried that, it seems not to work. I've done this with the newest mongodb drivers. Is there something i've got to be careful ? Like not having the ".so" libs in a include path? – Oliver Oct 09 '16 at 23:44
  • This is probably the best answer for the OP, as his archive is not prefixed by `lib`. It worked a treat for me. Thanks! – Mawg says reinstate Monica May 23 '17 at 09:20
  • Thank you so much! I tried the (-l) and (-L) method, and it fails. Too much headache. Your way works. – J. Doe Aug 09 '18 at 04:12
7

I had the similar problem when adding the libs in the C/C++ General->Paths & Symbols configuration screen.

Instead on the C/C++ Build -> settings screen under GCC C++ Linker / Libraries I added the library name without lib and .a in Libraries (-l) and adding the path in Libraries search path (-L). This solved my problem

ManuPK
  • 11,623
  • 10
  • 57
  • 76
Mauricio Quintana
  • 391
  • 1
  • 4
  • 13