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
30
votes
4 answers

Static Library and Swift

So I'm working on an iOS project in Swift, and I wanted to create a Static library with some useful stuff in it. My problem is when I try to build my lib in Xcode (version 6.3) I have a "Build Failed" followed by :…
Que20
  • 1,469
  • 2
  • 13
  • 27
30
votes
2 answers

gcc will not properly include math.h

Here is a minimal example outlining my problem test.c: #include #include main () { fmod ( 3, 2 ); } And here is the command I am issuing to compile test.c gcc -lm test.c -o test And here is the output I get when I issue the…
puk
  • 16,318
  • 29
  • 119
  • 199
28
votes
2 answers

C++ global variable not initialized when linked through static libraries, but OK when compiled with source

I have created a system that automatically registers function objects (functors) into a map based on the constructor of an global instance. In each cpp file that defines the functor, there's a global instance of the registrar class instance to…
t.g.
  • 1,719
  • 2
  • 14
  • 25
28
votes
1 answer

MinGW creating dll.a files ? What type of library files are those?

I am fairly familiar with Windows and Linux libraries compilation but as for today when I have seen MinGW on my Windows machine threw out dll.a and .a files after OpenCV compilation I have started to seriously start thinking. These are my \lib…
Patryk
  • 22,602
  • 44
  • 128
  • 244
27
votes
3 answers

C++ Statically linked shared library

I have a shared library used by a another application beyond my control which requires *.so objects. My library makes use of sqlite3 which needs to be statically linked with it (I absolutely need a self-contained binary). When I try to compile and…
Petr
  • 1,128
  • 2
  • 14
  • 23
27
votes
1 answer

Linking Windows DLL files from static libraries using CMake without hand-crafting unresolved symbol names

The Situation I'm using Visual Studio 2008 SP1 (Professional Edition, both for 32-bit and 64-bit builds). I'm seeking a workaround to what I believe is a very unhelpful "limitation" in Visual Studio. I find it quite surprising that the Visual…
bgoodr
  • 2,744
  • 1
  • 30
  • 51
27
votes
2 answers

How to compile Haskell to a static library?

Hey, I'm learning Haskell and I'm interested in using it to make static libraries for using in Python and probably C. After some googling I found out how to get GHC to output a shared object, but it dynamically depends on GHC`s libraries. The…
kuratkull
  • 327
  • 3
  • 9
27
votes
7 answers

What is the Microsoft Visual Studio equivalent to GCC ld option --whole-archive

When linking a static library against an executable, unreferenced symbols are normally discarded. In my case some otherwise unused objects are used to register their respective classes into a factory and if the objects are discarded, this…
fschmitt
  • 3,478
  • 2
  • 22
  • 24
27
votes
3 answers

static library, but I still need headers?

I have a bunch of projects that all could share a "common" static library of classes. What confuses me is if I make a static library out of these classes and link against it in my projects that I still need the headers of the classes in the static…
MLS
  • 615
  • 1
  • 8
  • 12
27
votes
4 answers

Xcode - symbol(s) not found for architecture x86_64 (iOS Lib)

I am building a static library. The build setting has the Architectures set to: $(ARCHS_STANDARD) which is shown as Standard Architectures (armv7, armv7s, arm64) I build the lib choosing iOS Device AND then using the simulator (for example…
Abdalrahman Shatou
  • 4,550
  • 6
  • 50
  • 79
27
votes
2 answers

How can I link with (or work around) two third-party static libraries that define the same symbols?

I can't be the only one to run into this. I have a C++ application that needs to link with one third-party and another static library set in an SDK. The SDK has, for some hideously frustrating reason, recompiled a subset of that same third-party…
rutgersmike
  • 1,183
  • 9
  • 18
27
votes
3 answers

merge static libraries into single

How to merge the static libraries into single one? I do have three static libraries libSignatureLibary_armv6.a , libSignatureLibary_armv7.a and libSignatureLibary_i368.a Now i want to merge this three file into one single library which may be…
kiran
  • 4,285
  • 7
  • 53
  • 98
26
votes
2 answers

Convert a static library target into a framework target in an Xcode project

I have a an Xcode project which produces a static library. My team plans all new development in Swift. It is not possible to add Swift files to the static library project. We are dropping support for iOS 7, so it is now possible to include…
Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117
26
votes
3 answers

Function names extraction from static library

I have a static library static_library.a How to list functions and methods realized there. or at least how to look is there concrete function 'FUNCTION_NAME' realized?
Max
  • 4,792
  • 4
  • 29
  • 32
26
votes
2 answers

Configuring Cocoapods with an existing static library and iOS application

I'm having trouble getting my workspace to compile correctly with Cocoapods. There are 3 projects in the workspace, each with their own target: libPods - Cocoapods static library with all the external dependencies libCommon - My static library…
user2393462435
  • 2,652
  • 5
  • 37
  • 45