I am a new iOS developer. I got a very basic doubt. I read at many places that we need to ship our .h file along with a .a file for a static library.
And .a files are compiled libraries, having entire implementation, which developers cannot read themselves, just to safe-guard implementer code.
And we need .h file to know what public functions are available. but then why cannot Xcode just decode .a file and use it directly instead of shipping another .h file. Xcode doesn’t need to show the .a implementation to developers, but instead can suggest developers with publicly available methods.
I dont see any logical reason why Apple didnt do this way. I am sure there is definitely a strong reason for shipping .h files. I want to know what could be the reason?
An
.afile is simply an archive of one or more.o(object) files. Object files contain the compiled machine code (for one specific operating system under a specific CPU architecture). The original source code is “lost”.The fact you probably didn’t know about: object files can contain binaries compiled from an arbitrary programming language. An
.hfile is C/C++/Objective C specific. It contains the data types and function prototypes you need to be able to use the functions/data types/… contained in binary form in an object file in C/C++/Objective C. You could e.g. write a Pascal library, compile it to a.afile and use that code in your Objective C program using an appropriate header (.h) file.You could also have only one header file (
.hfile) but e.g. 6 different.afiles: One compiled forMac OS X 64bit, one forMac OS X 32bit, one forLinux 2.6 64bit, one forLinux 2.6 32bit, one forFreeBSDand the last forOpenBSD.And last but not least, it wasn’t Apple who decided to go that way,
.aand.ofiles can be found on (at least) any Unix-like operating system and header files are the standard in C since the very first days.Usually if you port a library from Mac to Linux, you can use (most of) the code and the header file but have to compile a separate
.afile containing the object files compiled for Linux.