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
47
votes
1 answer

Determining the CPU architecture of a static library (LIB) on Windows

I just built libpng on a 64-bit Windows machine using VS2008. It produces a libpng.lib file inside the \projects\visualc71\Win32_Lib_Release directory (Configuration used being "LIB Release"). I used dumpbin to inspect this LIB…
Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
46
votes
1 answer

What's the difference between `-fembed-bitcode` and BITCODE_GENERATION_MODE?

I've been updating a static library to support bitcode, and from my research I found two ways to achieve that: Adding the fembed-bitcode flag to the Other C flags option in my project Build Settings (link) Adding a User-defined Setting with the key…
heitortsergent
  • 1,971
  • 2
  • 20
  • 23
45
votes
2 answers

How to build an Objective-C static library?

I have some Objective-C classes, which I am currently using in both a Cocoa application (Mac OS X) and a Cocoa-Touch application (iOS). Currently, when I update those classes, I have to copy those updated .h and .m files to both projects. Not that…
Alex
  • 64,178
  • 48
  • 151
  • 180
45
votes
4 answers

Android Studio + Volley

I'm new to Android Studio and I want to use Volley library for my app but i can't add the source as a library in Android Studio. I've searched the web but couldn't find anything. Everywhere is said to import as a library but I don't know how. I got…
Jilberta
  • 2,836
  • 5
  • 30
  • 44
44
votes
7 answers

Xcode custom build configuration causes "library/file not found" for static libraries

I have a workspace with a project which links with the static libraries in another project (which is also in the workspace). It's a problem in Kobold2D I haven't been able to resolve, even though I understand the cause, and I suppose it's similar to…
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
43
votes
1 answer

"undefined reference to" errors when linking static C library with C++ code

I have a test file (just for the link test) where I overload the new/delete operators with my own malloc/free library called libxmalloc.a. But I keep getting "undefined reference to" error as following when linking the static library, even I change…
user2153006
  • 467
  • 1
  • 4
  • 8
43
votes
8 answers

core data in a static library for the iPhone

I've built a static library that makes heavy use of the Core Data framework. I can successfully use the library in my external project, but ONLY if I include the .xcdatamodel file in the main project. That is less than ideal, since the point of the…
Vik
  • 1,301
  • 4
  • 16
  • 29
42
votes
4 answers

Xcode error: Missing required module 'Firebase'

The problem: I have a dynamic framework, which uses Firebase added by cocoapods. And I also have the App, which uses this dynamic framework. But when I try to build the project I got error Missing required module Firebase. I tried the…
Ilya Kharabet
  • 4,203
  • 3
  • 15
  • 29
42
votes
7 answers

Error: "File was built for archive which is not the architecture being linked (armv7s)"

I have built my own Static C++ Library, which is built with the settings: Architectures: armv7, armv7s Build Active Architectures Only: No Support Platforms: iOS Valid Architectures: armv7, armv7s The library project builds well and I got the .a…
ThomasCle
  • 6,792
  • 7
  • 41
  • 81
42
votes
5 answers

Using a static library in Qt Creator

I'm having a hell of a time finding documentation which clearly explains how to use a static library in Qt Creator. I've created and compiled my static library using Qt Creator (New=>Projects\C++ Library=>Set type to "Statically Linked Library"). It…
Dan O
  • 4,323
  • 5
  • 29
  • 44
41
votes
6 answers

Static libraries in Xcode 4

(My question has been asked here before but with no working answers that I can see. E.g. Xcode4 Workspace with Static library project & application project) I'm trying to use a library provided by a 3rd party. They provide the XCode project which…
TomSwift
  • 39,369
  • 12
  • 121
  • 149
41
votes
1 answer

How to build a library for both iPhone simulator and device?

I want to build a static library for iphone. I want to give my users the .a library which they can use for both simulator test and device test. Do I have to build two library in simulator mode and device mode? Is there any way to build a single one…
Chilly Zhong
  • 16,763
  • 23
  • 77
  • 103
40
votes
9 answers

How to resolve 'unrecognized selector sent to instance'?

In the AppDelegate, I'm alloc'ing an instance defined in a static library. This instance has an NSString property set a "copy". When I access the string property on this instance, the app crashes with 'unrecognized selector sent to instance'. …
4thSpace
  • 43,672
  • 97
  • 296
  • 475
40
votes
8 answers

VC++ resources in a static library

Is it possible to build resources into a static library and reuse them by simply linking with the library? I'm primarily thinking about the case where you call a function in the library which in turn accesses resources.
sharkin
  • 12,162
  • 24
  • 86
  • 122
40
votes
4 answers

How can I use an .a static library in swift?

I want to use my webrtc .a static library in swift. Can you help please? I read you can´t use static libraries in swift, is that true?
CarlosAndres
  • 585
  • 1
  • 5
  • 14