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

Force relink when building in QT Creator

I have a subdirs project which wraps a couple libraries and a main application. When I change something in one of the libraries the main application does not relink with them.. does anyone have a trick for getting an application to relink with its…
Dan O
  • 4,323
  • 5
  • 29
  • 44
20
votes
4 answers

Using "ar" to combine .o and .a files (Linux)

I'm trying to create a single static library which contains object files and existing static libraries which have all been compiled earlier in the build process. Is there an easy way to do this using "ar", or will I need to unpack (ar x…
psublue
  • 291
  • 1
  • 3
  • 9
20
votes
3 answers

link static lib in eclipse cdt

I am sorry! I have googled this a lot and cannot find an answer! It's dumb I know. I cannot link in static libraries(*.a) in eclipse cdt. I listed them all in Project->Settings-> GCC C++ linker -> Libraries. I used the absolute path to make sure…
JonnyCplusplus
  • 881
  • 3
  • 12
  • 22
20
votes
2 answers

What is the difference between .dylib and .a lib in ios?

I know what is compile and runtime in Objective c, (method swizzling is a runtime) but I want to know what draws the line between these two library? one .a and .dylib ? What purpose do they serve, other than stating one is static and the other is…
Kumar Utsav
  • 2,761
  • 4
  • 24
  • 38
20
votes
2 answers

How to list dependencies of c/c++ static library?

For a static library (.a file), how to list the module-level dependencies of it? I know for a shared library (.so), we can use objdump or readelf to do this: objdump -p test.so or readelf -d test.so I can get something like NEEDED …
bagebb
  • 221
  • 1
  • 2
  • 8
20
votes
1 answer

Building a distributable static library that uses cocoapods

I'm building a static library to be distributed to other iOS developers and having some trouble configuring the linker to allow the static library to be used in another app. I have used this guide to create a MyStaticLibrary.framework bundle…
stackunderflow
  • 754
  • 7
  • 18
20
votes
4 answers

How to update our static library architecture for suporting arm64 Build?

Few days ago i create static-library (Universal) that work's fine with Xcode5.0 SDK7. After Update Xcode5.1 with SDK7.1 that not work if i select simulator iPhone Retina(4-inch 64-bit). Then i am going to update my lib with Bellow setting change. I…
Nitin Gohel
  • 49,482
  • 17
  • 105
  • 144
20
votes
2 answers

Link a static library to a shared one during build?

I have a problem building a shared library with GCC/Linux. Currently this shared library is created with GCC/libtool option "-shared" and everything is fine. Now there are two additional, static libraries (.a-files) that have to be added to this…
Elmi
  • 5,899
  • 15
  • 72
  • 143
20
votes
3 answers

Can a C++ Static Library link to shared library?

Say I have a static C++ lib, static.lib and I want to call some functions from a C++ shared lib, say shared.lib. Is it possible? Now assume that I have another shared lib, say shared2.lib which links to static.lib but does not link to shared.lib.…
Canopus
  • 7,351
  • 11
  • 46
  • 57
19
votes
3 answers

How to load a custom binary resource in a VC++ static library as part of a dll?

I have custom binary resources (animated cursors) that would like to store as resources in a static lib in Visual Studio C++. It turns out that custom binary resources will not get loaded by ::LoadCursor() or found by ::FindResource() if it is a…
meissnersd
  • 1,272
  • 2
  • 12
  • 21
19
votes
3 answers

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

This question has been asked before, but digging into the documentation for the various development tools it seems like this is possible, just not obvious. Motivation: Making a static library for use by other iOS developers. Some symbols in the…
Dad
  • 6,388
  • 2
  • 28
  • 34
19
votes
4 answers

Difference between static and dynamic library in Xcode for iPhone

What is the difference between a static and dynamic library in XCode? And why doesn't Apple allow us to use dynamic libraries in our iOS applications?
prajakta
  • 673
  • 6
  • 26
19
votes
3 answers

How to import Objective C static library to Swift Framework?

I’m writing a dynamic Framework (Proto.framework) for OS X in Swift. I want to include code from a static library (libstat.a) which is written in Objective C. Here’s what I’ve got: // Dynamic.swift in Proto.framework class Dynamic { func…
jbrennan
  • 11,943
  • 14
  • 73
  • 115
19
votes
4 answers

How do i compile a static library (fat) for armv6, armv7 and i386

I know this question has been posed several times, but my goal is slightly different with regard to what I have found searching the web. Specifically, I am already able to build a static library for iPhone, but the final fat file I am able to build…
Massimo Cafaro
  • 25,429
  • 15
  • 79
  • 93
19
votes
5 answers

Static library built for archive which is not the architecture being linked (x86_64)

I am experiencing what seems to be the same problem when I try to compile two different programs. Each of them creates first a static library and then the main application linking that library. I am working on Mac OS Mavericks with gcc 4.7.2.…
ChronoTrigger
  • 8,459
  • 1
  • 36
  • 57