Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 965
Avihai Marchiano Avatar asked Jul 24 '12 18:07

Avihai Marchiano


People also ask

How static library is linked?

In computer science, a static library or statically-linked library is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable.

How to link a library in c++ Eclipse?

Similarly, to add a library file to be linked in Eclipse CDT: Right-click on the project name in Project Explorer, choose Properties > C/C++ Build > Settings > Tool Settings. Go to Cross G++ Linker > Libraries > Libraries. Click the + button and add the name of the library file, omit the file extension.

How do I link a static library in Visual Studio?

On Property Pages, go to C/C++->General->Additional Include Directories and provide the path, where the header file of the library that you want to use is located. Then go to Linker->General->Additional Library Directories and specify the path, where your . lib file is located.

What is linking GCC?

Linking is performed when the input file are object files " .o " (instead of source file " . cpp " or " . c "). GCC uses a separate linker program (called ld.exe ) to perform the linking.


1 Answers

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.

like image 196
Avihai Marchiano Avatar answered Oct 08 '22 05:10

Avihai Marchiano