Avihai Marchiano
Avihai Marchiano

Reputation: 3927

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

Upvotes: 14

Views: 32824

Answers (3)

Raging Software
Raging Software

Reputation: 741

I built the Botan cryptography library as a static library, for reasons I don't want to go into here, and when I followed all the steps on the interwebs, add the library paths and specify the library name without "lib" and ".a", my project built just fine, however, when I ran it, I kept getting "The program terminated unexpectedly" (or similar) errors. Finally I figured out how to fix it. In Menu Bar, go to Project > Properties > C/C++ Build > Settings > Cross G++ Linker and add -static between ${COMMAND} and ${FLAGS}, so the whole line looks like:

${COMMAND} -static ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}

Yours may vary. I'm using Eclipse Luna Service Release 2 (4.4.2), with mingw-w64 mingw-builds project w/gcc 4.9.2 on Windows 8.1.

Upvotes: 1

user1166007
user1166007

Reputation: 41

Add library path/file to: Properties - C/C++ Build - Settings - GCC C++ Linker - Miscellaneous - Other objects

Upvotes: 4

Avihai Marchiano
Avihai Marchiano

Reputation: 3927

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.

Upvotes: 17

Related Questions