How to build .dylib exporting only wanted symbols?

I built a dylib (dynamic library) on Mac OS X using XCode 2.4.1 yesterday.
When I open the .dylib file with a Text Editor I can see all my variables, functions, etc… as human readable text in there.
I don’t want this, so I created a “Exported Symbols File” where only the 6 functions I want to be accessible are declared in (with underscores preceeding them).
Well, guess what, after recompiling and opening with Text Editor I still see all the other symbols in there that should not be there.

What I want is something like __declspec(dllexport) on Windows. When use __declspec(dllexport) before functions, only these functions will be human readable in the resulting .DLL, all other symbols will be thrown away.

How can I do this on Mac?

Perhaps this question seems stupid, but I’ve searched through the whole Internet and also read the Apple Developer notes, but I couldn’t get it the way I want.

Yeah, it’s quite well hidden - the thing you’re after is attribute ((visibility(“default”)))

Tried that too, but doesn’t work either. Seems to be the same thing than creating and using an “exported symbols list”.

Let’s say I wanted to make a static library (.a) instead of a dynamic (.dylib).
How would the procedure be then?

Oh, I misunderstood what you’re asking. Maybe you just mean you want to strip the executable? (with the unix strip command)

Yes, but on static libraries this command just doesn’t work for me.

For instance, using strip -u -r libMYLIB.a gives me:
strip: symbols referenced by relocation entries that can’t be stripped in: …


I also tried stripping with a file where these 2 functions plus my to be exported symbols are listed in. doesn’t work either.

Actually, static libraries probably can’t be stripped - on unix they’re just like a zip file of all the object files, I think…

To answer my own first initial question for those who are interested:


the FILE_CONTAINING_EXPORTS_LIST is a text file containing all to be exported functions row by row. Don’t forget _ in front of C symbols