Wednesday, 15 January 2014

export - xcode 4.6 symbol visibility -



export - xcode 4.6 symbol visibility -

i have slight problem or misunderstanding hiding symbols in xcode 4.6. have searched everywhere in web , cant find posts having same issue.

currently have created framework project simple header file containing so:

class test { public: test(){} test(){} }; int a(int n) {return n;} __attribute__((visibility("hidden"))) int b(int n) {return n;} __attribute__((visibility("default"))) int c(int n) {return n;} class x { public: virtual ~x(); }; class __attribute__((visibility("hidden"))) y { public: virtual ~y(); }; class __attribute__((visibility("default"))) z { public: virtual ~z(); }; x::~x() { } y::~y() { } z::~z() { }

in project settings have made sure "symbols hidden default" switched yes , hence functions int c , class z exported or visible other projects.

i build framework no errors or warnings , copy/add cocoa application testing.

i able include header file still able access classes , functions.

i hope can explain why or going wrong or have encountered problem before?

regards

your problem is, declaring in header file. means if symbols not exported, when import header file file, these symbols re-created in project imported header , of course of study available within project.

i'm trying explain simpler sample. assume have 2 files, mylib.h , mylib.c.

mylib.h:

int add(int a, int b);

mylib.c:

int add(int a, int b) { homecoming + b };

if give add hidden visibility , compile library (mylib), library have no symbol add (as hidden). result, if include mylib.h file, create phone call add function there , link file against mylib, linker error, since linker complain cannot find implementation add (it has declaration h file).

however, if pack function header itself, mylib.h is:

int add(int a, int b) { homecoming + b };

and give add hidden visibility, library have no symbol add, when include header file, header create symbol add in file imported , of course of study not linker error , able phone call add.

importing h file means copying whole content of h file location import instruction has been found. think it: if re-create whole content of h file in question top of file including it, of course of study symbols declared there visible , usable in current project. why wouldn't visible or useable? not in library, yes, in header , compiled when other project compiled.

symbols supposed not visible outside current project ("hidden" symbols) should never appear in public header file of framework. why announce existence of symbols in header files cannot used anyway? actually, in cases not exposing symbols in header file plenty prevent people using them. reason not exporting them either if symbol exists, can used, if not exposed header file (therefor need write own header file or declaring external symbol straight in code). making symbols hidden safeguard create sure cannot used under circumstances.

xcode export visibility xcode4.6

No comments:

Post a Comment