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
126
votes
9 answers

How to merge two "ar" static libraries into one?

I have 2 static Linux libraries, created by ar cr, libabc.a and libxyz.a. I want to merge them into one static library libaz.a. How can I do this. I want to create a merged static library, not to give both libraries to final link of applications.
osgx
  • 90,338
  • 53
  • 357
  • 513
124
votes
4 answers

"Do Not Embed", "Embed & Sign", "Embed Without Signing". What are they?. What they do?

We have 3 new options in "Frameworks, Libraries, and Embedded Content" section of Xcode11 Beta for adding libraries. Xcode Libraries section screenshot Can anyone explain what they do?
Shreeram Bhat
  • 2,849
  • 2
  • 11
  • 19
120
votes
5 answers

iOS Static vs Dynamic frameworks clarifications

I have to admit that with the release of iOS 8 I am a bit confused about dynamic and static frameworks in iOS. I am looking for a way to distribute a library that I created, and I need to support iOS 7 and above. (Note: This will be a proprietary…
csotiriou
  • 5,653
  • 5
  • 36
  • 45
115
votes
5 answers

Linking libstdc++ statically: any gotchas?

I need to deploy a C++ application built on Ubuntu 12.10 with GCC 4.7's libstdc++ to systems running Ubuntu 10.04, which comes with a considerably older version of libstdc++. Currently, I'm compiling with -static-libstdc++ -static-libgcc, as…
Nick Hutchinson
  • 5,044
  • 5
  • 33
  • 34
110
votes
21 answers

Why do I get iOS linker errors with my static libraries?

I have a problem with linking my mixed language framework to a project. I create a framework with Swift and Objective-C classes. The main logic was stored in the Swift file. For example the class with a method that calls NSLog("Swift log was…
96
votes
5 answers

What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?

What is inside of a .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library? How come there is no need for a .lib file in dynamically linked dynamic library and also that in static linking, the .lib file…
Sulla
  • 7,631
  • 9
  • 45
  • 71
94
votes
4 answers

Trying to include a library, but keep getting 'undefined reference to' messages

I am attempting to use the libtommath library. I'm using the NetBeans IDE for my project on Ubuntu linux. I have downloaded and built the library, I have done a 'make install' to put the resulting .a file into /usr/lib/ and the .h files into…
KU1
  • 941
  • 1
  • 7
  • 4
92
votes
18 answers

Xcode 4 can't locate public header files from static library dependency

Alternate titles to aid search Xcode can't find header Missing .h in Xcode Xcode .h file not found lexical or preprocessor issue file not found I'm working on an iOS application project which came from Xcode 3. I have now moved to Xcode 4 my…
Richard Stelling
  • 25,607
  • 27
  • 108
  • 188
86
votes
1 answer

What is the use of .exp and what is the difference between .lib and .dll?

During compilation and linking, what is use of .exp? What is the difference between .lib and .dll? I know that .lib will be used, while linking and .dll will be used when running the program. But what exactly is the difference between .lib and…
Vineel Kumar Reddy
  • 4,588
  • 9
  • 33
  • 37
86
votes
5 answers

"relocation R_X86_64_32S against " linking Error

I'm Trying to Link a static Library to a shared library , I'm Getting the Following error /usr/bin/ld: ../../../libraries/log4cplus/liblog4cplus.a(fileappender.o): relocation R_X86_64_32S against `a local symbol' can not be used when making a…
Thiyagarajan
  • 1,271
  • 1
  • 14
  • 19
85
votes
3 answers

Link Binary with libraries VS Embed Frameworks

What's the difference in the build phases between putting a framework in "Link binary with libraries" or in "Embed frameworks"?
Alberto Schiariti
  • 1,546
  • 2
  • 15
  • 31
79
votes
2 answers

static variable link error

I'm writing C++ code on a mac. Why do I get this error when compiling?: Undefined symbols for architecture i386: "Log::theString", referenced from: Log::method(std::string) in libTest.a(Log.o) ld: symbol(s) not found for architecture…
subzero
  • 3,420
  • 5
  • 31
  • 40
79
votes
3 answers

How to check if a static library is built for 64-bit?

I just built a static library for iOS with the build setting for Architectures set to $(ARCHS_STANDARD_INCLUDING_64_BIT). I want to make sure that the .a library is properly including that architecture, but when i run lipo -info on it, I…
Joel Fischer
  • 6,521
  • 5
  • 35
  • 46
76
votes
3 answers

Xcode: Copy Headers: Public vs. Private vs. Project?

I'm building a Cocoa Touch Static Library. How should I decide whether to copy a header file as public, private, or project?
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
75
votes
2 answers

g++ linker: force static linking if static library exists?

I've a program which links to many libraries. g++, by default, prefers to link to shared libraries, even if the corresponding archive exists. How can I change this preference to prefer static archives over dynamic libraries, if a static archive…
kumar
  • 2,696
  • 3
  • 26
  • 34