开发者

How to deal with dependencies in shared libraries, unix

I have created a dynamic(.so) library which bundles some functionality for a storage backend that I need.

As it is, it offers a known interface and provides ba开发者_StackOverflowckends for things like memcached, mysql, sqlite... etc.

Now my problem is that my shared library depends on libmemcached, on libsqlite3, on libmysqlclient.. etc., and I don't know how to pack it since clients that only want sqlite wouldn't need to have libmemcached installed.

I've been thinking on splitting it on different libraries but it seems like I'll end up with almost 20 .so libraries and I don't like that idea.

Any alternative?


One alternative is to put an interface within the shared library you made, which allows it to load dependencies at runtime. So, as an example you can have separate init functions for different components:

init_memcached();
init_sqlite();

You implement these initialization functions using dlopen() and friends.


You can use dynamic loading using dlsym and dlopen. The advantage of this approach is your application will run fine when the shared library is not found on client side.


You could load only needed shared libraries during run-time, but in my opinion, it is not so good approach.

I would split the shared library, but not into 20 libraries. See if you could group some common functionality.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜