Prevent calling of functions in static library
I have created a static library using xcode for IOS. In C++, if a class is needed to be called from other programs, it will need to add "__declspec(dllexport)" to export the class. In xcode, no export is needed. Is there a way to prevent the calling of the functions in the library that I do开发者_运维知识库 want want to expose to other programs?
Thanks.
http://developer.apple.com/library/mac/#documentation/MacOSX/Conceptual/BPFrameworks/Tasks/ExportingInterfaces.html
Exporting Your Framework Interface
When you build a framework or application using Xcode, the linker exports all of the symbols defined in your code by default. For a shipping framework with many symbols, this can lead to performance problems at runtime. When a framework is loaded, the dynamic link editor loads the symbols associated with the framework. If a framework contains a number of private functions, the symbols for those private functions are not going to be used but are still loaded along with symbols for the public functions. Loading these extra symbols not only wastes memory, it also requires more work to walk the list during a symbol lookup.
In Xcode, you can limit the symbols exported by your executable by specifying an exports file in your linker options.
Creating Your Exports File
An exports file is a simple text file (.txt or other text file extension) that contains the list of symbols you want to export. To create the file, add a new empty file to your Xcode project. To this file, add the list of symbols you want to export, one symbol per line.
For ANSI C-based code, you can usually just prefix an underscore character to the name of a function or variable to get the symbol name. For languages like C++, which uses mangled symbol names, you may need to run the nm tool to get the list of existing symbol names. Run nm with the -g option to see the currently exported symbols. You can then copy the output from the tool and paste it into your exports file, removing any extraneous information. The following text shows some sample output for a Cocoa framework generated by nm:
U .objc_class_name_NSDate
b000ad54 T _InitCocoaFW
b000aea8 T _addNumbers
b000ade8 T _getInitDate
U _objc_msgSend
To export the framework functions specified in this output, you would create a text file with this text:
_InitCocoaFW
_addNumbers
_getInitDate
精彩评论