# Hide exported Symbols in .so

This topic is 3749 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I've ported a DLL from Win32 to Linux (.so). Basically, the DLL contains a bunch of classes which are derived from pure virtual interfaces. The DLL only exports 1 function (getFactory) which returns a pointer to one of those pure virtual interfaces. The aren't any other symbols exported. Now, when I take a look at my .so using "nm -D" almost all of my classes are visible. I don't want anyone to see my classes, function, etc. but the one I have exported in my Windows DLL (namely getFactory). Is there any way to hide those symbols? Thanks, Metron

##### Share on other sites
I believe there are ways of doing this using some Gcc attributes, though off hand I can't remember the exact syntax of attributes.

##### Share on other sites
I never tried it with shared libs, but maybe using strip is worth a shot.

##### Share on other sites
Use a configure script to see if the g++ compiler supports the visibility attribute and use macros just as you would do so for windows (import/export).

#ifdef WIN32#	ifdef EXPORT...#	else....#	endif#	define DLL_LOCAL #else#	ifdef __GNU__#		if (GCC_SUPPORTS_VISABLE == 1) /*defined by configure*/#			ifdef EXPORT#				define DLL_API __attribute__ ((visibility("default")))#			else#				define DLL_API __attribute__ ((visibility("default")))#			endif#			define DLL_LOCAL __attribute__ ((visibility("hidden")))#		else#			define DLL_API#			define DLL_LOCAL#		endif#	endif#endif

##### Share on other sites
Quote:
 Original post by MetronIs there any way to hide those symbols?

As with Windows, there are two different ways.

First, there is the GCC visibility attribute as pointed out by dmail. You use it just lke the Windows import/export declspec (it has a different meaning, but the defined symbol goes in the same place so you just need to define a macro in a header file as appropriate). Problem with this method is it only works in GCC 4.2 or later: the attribute was available in 4.1 but cuase dhorrible things to go wrong with standard library symbols.

Second, you can create a version list file and feed it to the linker (like the old Windows .def files). This is not the preferred way, but is the only way if you're using a pre-4.2 toolchain.

Finally, the end effect of using the version list or visibility attribute is that it marks some symbols as local, and others as global. It doesn't remove those symbols. For that, you will want to run the strip -x command. Most packaging systems do this automatically as they package your library.

1. 1
2. 2
3. 3
Rutin
16
4. 4
JoeJ
13
5. 5

• 9
• 14
• 10
• 25
• 9
• ### Forum Statistics

• Total Topics
632645
• Total Posts
3007632
• ### Who's Online (See full list)

There are no registered users currently online

×