30

What exactly are .a (e.g. libcrypto.a) files and what do they consists of? Is it .m or .o or .h or .c files?

How does IOS SDK/Xcode understands them? And if we include the .a file in our xcode project, do we need to copy the correspondng sources file too?

Lebyrt
  • 1,376
  • 1
  • 9
  • 18
chetan
  • 633
  • 1
  • 10
  • 26

1 Answers1

49

.a files are static library files. They "contain" one or more .o files, i.e. compiled code. To use them, you (often) need the header (.h) files that correspond to the compiled code, but you do not need the source code (.c, .m) itself.

The .a files are produced with the ar utility, and the linker (ld) that is (usually) invoked by your compiler knows their format and how to extract the relevant pieces of code from the archive and into your executable.

Mat
  • 202,337
  • 40
  • 393
  • 406
  • Thanks for your prompt reply Mat, I have created a static library .a file for a sample project and copied the header and .a file in another project. But when I try to access the methods in debug mode, the control is pointing to the methods of corresponding .m file which i have created .a file. why is it opening the .m file, if I added just the its .h and .a file. – chetan Nov 22 '11 at 10:01
  • Debug information contains file names and line numbers. This information is included in the `.o` files so that debuggers can show you what source code generated the instructions you're looking at. Without that, you'd only see assembly which is not as useful. Your IDE can map that debug information to the actual source code files if it has enough information. – Mat Nov 22 '11 at 10:04
  • Thanks, So you say that, only in debug mode, the IDE points to the source file and not in runtime because of .o file? If I remove the project from its location, in debug mode, it throws error saying "xcode could not locate source file" and breaks there. But when I go for runtime, there is no error – chetan Nov 22 '11 at 10:14
  • Depends on your exact settings. If you compile the source for your static library without debug information, the IDE can't point anywhere (and won't try) because it doesn't have the information to do so (the source code is _not_ present in the `.o` files, only debug information). If you compile the library _with_ debug information, the IDE will try to locate the corresponding files. – Mat Nov 22 '11 at 10:16
  • Im trying to understand something now. Till now I'm building the .a file, by placing Simulator mode (debug) If I do it as Simulator (release) , it should not have debug information right? – chetan Nov 22 '11 at 10:21
  • I don't know. Depends exactly what compiler and compiler flags are passed when you select those modes. Why is this a problem? – Mat Nov 22 '11 at 10:22
  • we are building a secure application by creating a static library file and sharing it, should not have glitches while its execution integrated with some other application in Xcode. – chetan Nov 22 '11 at 10:31
  • Then either strip the debug information, or ship the source code with it. – Mat Nov 22 '11 at 10:32
  • Please search a bit. "xcode strip debug information" gives good hits – Mat Nov 22 '11 at 10:35
  • hi Mat, thanks for the search info and one more quesion Do we have a shared pool of memory or directory in iphone, so that applications can read and write (access) files in this area. – chetan Nov 22 '11 at 14:58
  • That has nothing to do with the question you posted here. If you have other questions, post a new question, but make sure you _search_ (this site and your favorite search engine) before, I'm pretty sure that's been asked a lot. – Mat Nov 22 '11 at 15:09
  • Do I need to include my .a files in the Compile Sources, or Copy Bundle Resources phase of the Build Phases? Or just having it in the "Link with Binary Libraries" is fine? – Lucas P. Nov 07 '19 at 09:54