Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

link static lib in eclipse cdt

Tags:

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...

like image 407
JonnyCplusplus Avatar asked Feb 10 '11 01:02

JonnyCplusplus


People also ask

What is CDT in Eclipse?

The CDT is Eclipse's C/C++ Development Tooling project. It is an industrial-strength C/C++ IDE that also serves as a platform for others to provide value-added tooling for C/C++ developers.

How do I add a library in Makefile?

a , in which case you also need to add -lmine to the linker line (after the object files that reference the library). You have a file libmine that is a static archive, in which case you simply list it as a file ./libmine with no -L in front. You have a file libmine. a in the current directory that you want to pick up.


2 Answers

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.

like image 54
Ralf Avatar answered Oct 25 '22 22:10

Ralf


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...

like image 39
jww Avatar answered Oct 25 '22 20:10

jww