1 year ago

#374338

test-img

Pack Yak1

Shared libraries and convenience when compiling

Context

I'm new to making libraries, and I'm trying to make a shared library. I made libfoo.so and stored in in <path>/bin/shared directory. My library has some headers h1.hpp... which are stored in <path>/src/include.

Header files

Right now, when I try to compile bar.cpp from another environment, I run

g++ -L<path>/bin/shared bar.cpp -o bar -lfoo

but it says fatal error: h1.hpp: No such file or directory. The only way I can compile it is if I add

-I<path>/src/include

when compiling. Is there something I can do differently to avoid users of my library having to add this -I flag?

rpath

I also realize that users of my library would need to add

-Wl, -rpath=<path>/bin/shared

when compiling their programs. Is this something I can expect my users to figure out themselves or is there something I can do to make using the library more convenient?

c++

shared-libraries

0 Answers

Your Answer

Accepted video resources