Justine Pagarao
Justine Pagarao

Reputation: 11

Unable to link created .so file to main.cpp

Good day! I am running a c++ project main.cpp in eclipse. i want to use my existing .so file and link it in main.cpp. I am searching about this but cant find the right method for me. I'm using ubuntu. Thanks for any help!

Upvotes: 1

Views: 505

Answers (1)

zxcdw
zxcdw

Reputation: 1649

To link against a library you need to supply the compiler(or the linker) a -l flag and the library name. For example, if you want to link against a library called libjustine.so, you would supply your compiler(gcc if C, g++ if C++) a flag -ljustine and then the compiler would instruct the linker to link against a file libjustine.so in the library path (usually at least /usr/lib/ and /usr/local/lib/).

However, if you want to define your own library directory, for example a lib/ directory inside your project directory, you need to use the -L flag and supply the desired library directory(relative to the current directory) that way, for example -L/lib/ so the compiler can instruct the linker to look for the desired library from lib/ instead of for example /usr/lib/ where it looks for the file by default.

Upvotes: 1

Related Questions