How to create static library for iOS without making all symbols public?

This is really not possible, I'm sorry to say. It has to do with the way static libraries work. A static library is little more than a bunch of object o files bundled together, but a dynamic library is a loadable binary image, just like an executable Suppose you have four files common.

C defines common which is "private fn1. C defines fn1 which calls common fn2. C defines fn2 which calls common other.

C defines other In a dynamic library the linker bundles everything up into one big chunk of code. The library exports other fn1 and fn2 You have to load the entire library or none of it, but two programs can both load it without putting multiple copies in memory. The entry point to common is simply missing from the symbol table — you can't call it from outside the library because the linker can't find it Note that an application and a shared library have essentially the same format: an application is basically a shared library that only exports one symbol main (This is not exactly true, but close.) In a static library the linker never runs.

The files all get compiled into *. O files and put into a *. A library archive.

Internal references will be unresolved Suppose your application calls fn1 The linker sees an unresolved call to fn1 and then looks through the libraries. It finds a definition for fn1 in fn1.o. Then the linker notices an unresolved call to common so it looks it up in common.o.

This program won't get the code from fn2. C or other. C, because it doesn't use the definitions from those files Static libraries are very old, and they do not have any of the features of dynamic libraries.

You can think of a static library as basically a zip file full of compiled source code, unlike a dynamic library which is linked together. Nobody ever bothered to extend the archive format to add symbol visibility. When you link with a static library, you get the same result as if you had added the library's source code to your program The short version: A dynamic library has one symbol table of all of the exported symbols, but none of the private symbols.

In the same way, an object file has a list of all of its extern symbols but none of the static ones. But a static library has no symbol table, it is just an archive.So there is no mechanism to make code private to a static library (other than defining objects static but that doesn't work for Objective-C classes) If we knew why you were trying to do this, perhaps we could give you a suggestion. (Is it for security?

Name clashes? All of these questions have solutions. ).

This is really not possible, I'm sorry to say. It has to do with the way static libraries work. A static library is little more than a bunch of object *.

O files bundled together, but a dynamic library is a loadable binary image, just like an executable. Suppose you have four files, common. C defines common, which is "private" fn1.

C defines fn1, which calls common. Fn2. C defines fn2, which calls common.Other.

C defines other. In a dynamic library, the linker bundles everything up into one big chunk of code. The library exports other, fn1, and fn2.

You have to load the entire library or none of it, but two programs can both load it without putting multiple copies in memory. The entry point to common is simply missing from the symbol table — you can't call it from outside the library because the linker can't find it. Note that an application and a shared library have essentially the same format: an application is basically a shared library that only exports one symbol, main.(This is not exactly true, but close.) In a static library, the linker never runs.

The files all get compiled into *. O files and put into a *. A library archive.

Internal references will be unresolved. Suppose your application calls fn1. The linker sees an unresolved call to fn1, and then looks through the libraries.

It finds a definition for fn1 in fn1.o. Then the linker notices an unresolved call to common, so it looks it up in common.o. This program won't get the code from fn2.

C or other. C, because it doesn't use the definitions from those files. Static libraries are very old, and they do not have any of the features of dynamic libraries.

You can think of a static library as basically a zip file full of compiled source code, unlike a dynamic library which is linked together. Nobody ever bothered to extend the archive format to add symbol visibility. When you link with a static library, you get the same result as if you had added the library's source code to your program.

The short version: A dynamic library has one symbol table of all of the exported symbols, but none of the private symbols. In the same way, an object file has a list of all of its extern symbols but none of the static ones. But a static library has no symbol table, it is just an archive.

So there is no mechanism to make code private to a static library (other than defining objects static, but that doesn't work for Objective-C classes). If we knew why you were trying to do this, perhaps we could give you a suggestion.(Is it for security? Name clashes?

All of these questions have solutions. ).

I don't want to write a new answer, because you have written a great explanation here, but it seems the solution, then, would be to combine all source files into one file that is compiled as a single unit. (Automatically, not manually. ) The SQLite project does something like this.

– benzado Sep 7 at 1:03 @benzado: That doesn't work for Objective C classes. – Dietrich Epp Sep 7 at 1:27 Fair enough, so even if he could hide other symbols (functions, constants) the class names would still be exposed, so there's no point. – benzado Sep 7 at 1:45 thanks @dietrich, that's about what I figured.

I had hoped there might be a clever solution I'd missed, but alas it appears not :) The other option I've considered would be to rename all the objective C classes and so on to make sure they will not conflict. – Dad Sep 7 at 5:26.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions