Search code examples
c++eclipse-cdt

eclipse-cdt how to link with static library


Fist i am confused should i set libraries under Linker/Libraries or to set them under "path and symbol". i think that they are the same. am i correct?

any way for my question - i need to link static library , so i tried few things:

First try I try to add gtest (this is the library) and gtest path in the link library. in this way its compiled and linked correct , but failed in runtime , because when it tried to load shared library (i want static library !) error is

error while loading shared libraries: libgtest.so.0

Second try - I try do define it in path and symbol add to libraries the complete path '/root/workspace/gmock/gtest/lib/.lib/libgtest.a' . in this case i got error in the linkage :

g++ -L/root/workspace/gmock/lib/.libs -L/root/workspace/gmock/gtest/lib/.libs -o "playground"  ./src/p.o ./src/playground.o   -lpthread -l/root/workspace/gmock/gtest/lib/.lib/libgtest.a -l/root/workspace/gmock/lib/.lib/libgmock.a
/usr/bin/ld: cannot find -l/root/workspace/gmock/gtest/lib/.lib/libgtest.a

This post dosnt give an answer and not explain how you define differently linked against static vs shared.

Thank you


Solution

  • After lot of research and not related answer. found it!!! I found it in this useful link for eclipse-cdt

    Apparently the library need to exist in the workspace.