Questions tagged [static-libraries]

A static library is an archive of object files. Used as a linker input, the linker extracts the object files it needs to carry on the linkage.

The needed object files are those that provide the linker with definitions for symbols that it finds are used, without definition, in other input files. The needed object files, and no others, are extracted from the archive and input to the linkage exactly as if they were individual input files in the linkage command and the static library was not mentioned at all.

Linkers may differ as to whether the position of a static library in the sequence of input files affects its availability to be searched for needed object files. Some linkers (e.g. GNU ld) will search a static library only to obtain definitions for unresolved symbol references used in earlier input files. For such a linker, success requires a static library to be input after all other files that depend on it for symbol definitions. Other linkers (e.g. Microsoft link) will search a static library to obtain a definition for any otherwise unresolved symbol reference.

A linker will normally support an option (GNU ld: --whole-archive, MS link: /WHOLEARCHIVE) to override the default processing of static libraries and instead link all the contained object files, whether they are needed or not.

A static library contributes nothing to a linkage except the object files that are extracted from it, which may be vary in different linkages. It is to be contrasted with a shared library, another kind of file altogether with a very different role in linkage.

4482 questions
676
votes
9 answers

Difference between static and shared libraries?

What is the difference between static and shared libraries? I use Eclipse and there are several project types including Static Libraries and Shared Libraries? Does one have an advantage over the other?
Mohit Deshpande
  • 53,877
  • 76
  • 193
  • 251
407
votes
8 answers

File is universal (three slices), but it does not contain a(n) ARMv7-s slice error for static libraries on iOS, anyway to bypass?

I upgraded Xcode version and when using external static libraries, I get this message: ld: file is universal (3 slices) but does not contain a(n) armv7s slice: /file/location for architecture armv7s clang: error: linker command failed with exit…
Dafna Elazazer
  • 4,083
  • 2
  • 13
  • 6
293
votes
5 answers

DLL and LIB files - what and why?

I know very little about DLL's and LIB's other than that they contain vital code required for a program to run properly - libraries. But why do compilers generate them at all? Wouldn't it be easier to just include all the code in a single…
Xonara
  • 3,113
  • 5
  • 22
  • 12
286
votes
2 answers

What's the difference between .so, .la and .a library files?

I know an .so file is a kind of dynamic library (lots of threads can share such libraries so there is no need to have more than one copy of it in memory). But what is the difference between .a and .la? Are these all static libraries? If dynamic libs…
hugemeow
  • 7,777
  • 13
  • 50
  • 63
283
votes
27 answers

Can't use Swift classes inside Objective-C

I try to integrate Swift code in my app.My app is written in Objective-C and I added a Swift class. I've done everything described here. But my problem is that Xcode haven't created the -Swift.h file, only the bridging headers. So I created it, but…
dnnagy
  • 3,711
  • 4
  • 24
  • 34
233
votes
3 answers

Library? Static? Dynamic? Or Framework? Project inside another project

I have an existing iOS app and want to add a large chunk of code that I've been developing as another project just for ease of testing. The new chunk basically deals with saving an image to various sharing services, etc.. Because that sharing code…
pizzafilms
  • 3,829
  • 4
  • 24
  • 39
228
votes
8 answers

How to See the Contents of Windows library (*.lib)

I have a binary file - Windows static library (*.lib). Is there a simple way to find out names of the functions and their interface from that library ? Something similar to emfar and elfdump utilities (on Linux systems) ?
Nick Borodulin
  • 3,065
  • 4
  • 21
  • 21
188
votes
2 answers

Telling gcc directly to link a library statically

It feels strange to me to use -Wl,-Bstatic in order to tell gcc which libraries I want to link with statically. After all I'm telling gcc directly all other information about linking with libraries (-Ldir, -llibname). Is it possible to tell the gcc…
Elazar Leibovich
  • 32,750
  • 33
  • 122
  • 169
185
votes
3 answers

How to compile a static library in Linux?

I have a question: How to compile a static library in Linux with gcc, i.e. I need to compile my source code into a file named out.a. Is it sufficient to simply compile with the command gcc -o out.a out.c? I'm not quite familiar with gcc, hope anyone…
Summer_More_More_Tea
  • 12,740
  • 12
  • 51
  • 83
162
votes
5 answers

Why do we use use_frameworks! in CocoaPods?

I have used use_frameworks! in CocoaPods Podfile many times. I just wonder why do we use it? I couldn't get the straight forward answer of it. Example: platform :ios, '8.0' use_frameworks! target "CityWhether" do pod 'Alamofire' pod…
harikrista
  • 1,621
  • 2
  • 11
  • 8
161
votes
6 answers

Objective-C categories in static library

Can you guide me how to properly link static library to iPhone project. I use static library project added to app project as direct dependency (target -> general -> direct dependencies) and all works OK, but categories. A category defined in static…
Vladimir
  • 7,670
  • 8
  • 28
  • 42
151
votes
3 answers

When should we use "embedded binaries" rather than "Linked Frameworks" in Xcode?

There is a good question about the difference between those two options as described in Link Binary with libraries VS Embed Frameworks. Seems like we have options to use them both, just wonder which case we should use embedded binaries better, or…
Forrest
  • 122,703
  • 20
  • 73
  • 107
138
votes
4 answers

How do I tell CMake to link in a static library in the source directory?

I have a small project with a Makefile which I'm trying to convert to CMake, mostly just to get experience with CMake. For purposes of this example, the project contains a source file (C++, though I don't think the language is particularly relevant)…
David Z
  • 128,184
  • 27
  • 255
  • 279
137
votes
3 answers

Difference between framework and static library in xcode4, and how to call them

I am quite new to xcode and objective-c. I want to ask a very basic question. I saw that when "linking binary to libraries" in project settings, there are differences about framework and libraries, imported from other projects in workspace. First…
Leonardo
  • 9,607
  • 17
  • 49
  • 89
129
votes
8 answers

static linking only some libraries

How can I statically link only a some specific libraries to my binary when linking with GCC? gcc ... -static ... tries to statically link all the linked libraries, but I haven't got the static version of some of them (eg: libX11).
peoro
  • 25,562
  • 20
  • 98
  • 150
1
2 3
99 100