ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi all, I've ported code for a Windows DLL to Linux, but the shared library is over four times bigger than the DLL!
It's a fairly big code base but only a small number of functions is exported from the DLL (using a .def file). I found out that the static library on the other hand exports all functions. So what I believe is happening is that on Windows all functions which are unused by the exported functions get stripped from the DLL.
So my question is, how can I specify the functions that should be exported from the shared library, and how do I get the linker to minimize the binary size based on that limited set?
Here are some macros I've hacked to control exorting symbols from a shared object:
Code:
#ifndef DLL_PUBLIC
#if defined (_Windows)
#if defined (__GNUC__)
#define DLL_PUBLIC(type,name) __attribute__ ((dllexport)) type name
#define DLL_LOCAL(type,name) type name
#else
#define DLL_PUBLIC(type,name) type _export name
#define DLL_LOCAL(type,name) type name
#endif
#elif defined (__unix__) || defined (__UNIX__)
#define DLL_PUBLIC(type,name) __attribute__ ((visibility ("default"))) type name
#define DLL_LOCAL(type,name) __attribute__ ((visibility ("hidden"))) type name
#endif
#endif
Here are some macros I've hacked to control exorting symbols from a shared object:
Code:
#ifndef DLL_PUBLIC
#if defined (_Windows)
#if defined (__GNUC__)
#define DLL_PUBLIC(type,name) __attribute__ ((dllexport)) type name
#define DLL_LOCAL(type,name) type name
#else
#define DLL_PUBLIC(type,name) type _export name
#define DLL_LOCAL(type,name) type name
#endif
#elif defined (__unix__) || defined (__UNIX__)
#define DLL_PUBLIC(type,name) __attribute__ ((visibility ("default"))) type name
#define DLL_LOCAL(type,name) __attribute__ ((visibility ("hidden"))) type name
#endif
#endif
Here HttpValue won't be exported from the shared object, but HttpMime will.
Unfortunately that's not practical since there are many thousands of functions, and there's lots of third party source code. However, this did lead me to a GCC option to hide all functions by default: http://gcc.gnu.org/wiki/Visibility I have high hopes that this will reduce the library size to something more acceptable. So thanks for pointing me in this direction!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.