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
19
votes
2 answers

Include framework in Xcode static library?

In short: Is there a way to create a static library in Xcode such that when clients link with that library, they also link with the frameworks upon which that library depends? The problem: We have a shared Xcode project which contains multiple…
Jon-Eric
  • 16,977
  • 9
  • 65
  • 97
19
votes
3 answers

How can I create static library and can add just .a file on any project in ios

How can I create static library and can add just .a file on any project in ios. I tried doing this but couldn't do it. Thanks in advance
user2568616
18
votes
3 answers

File format differences between a static library (.a) and a shared library (.so)?

I know that there are lots of questions about the use cases of shared vs static libraries, this question is not about that. I am asking about differences in file format stored on disk. Why question is, what are the differences between the two? Or…
silverscania
  • 647
  • 1
  • 6
  • 16
18
votes
1 answer

How to link against Rust crate from integration tests in 'tests' folder when building static library?

I'm building a library in Rust that will be called from C/C++ code. Cargo.toml is configured to output the crate as a static library: [lib] crate-type = ["staticlib"] I have a test in tests/integration_test.rs: extern crate mylibrary; #[test] fn…
David Haynes
  • 933
  • 5
  • 14
18
votes
4 answers

How can I add a prebuilt static library in a project using CMake?

CLion: How can I add (or use) a prebuilt static library in my project?
ilw
  • 2,499
  • 5
  • 30
  • 54
18
votes
7 answers

handling dependencies for iOS Framework project

I've created iOS Framework project using this method: https://github.com/jverkoey/iOS-Framework Works pretty neat but I'm a little confused on how to include libraries/frameworks that are needed by my framework to work and, in particular, how to do…
Łukasz Sromek
  • 3,637
  • 3
  • 30
  • 43
18
votes
1 answer

CMake: How to create alias for installing different targets?

Suppose that I've got the following libraries: add_library(myLib_static STATIC ${SRC_FILES}) add_library(myLib SHARED ${SRC_FILES}) # installing header files install(FILES ${H_FILES} DESTINATION ${INSTDIRHEADER}) # installing…
B Faley
  • 17,120
  • 43
  • 133
  • 223
18
votes
3 answers

Is there any recommended lightweight pubsub service/library?

I'm building a small system that contains many parts and I want to use a message pub/sub service to communicate between parts. I read about some message queue services like RabbitMQ and ZeroMQ but I feel they are too complicated and feel like it was…
Yoshi
  • 563
  • 1
  • 6
  • 17
18
votes
1 answer

undefined reference to `inflate'

Trying to link against a static assimp library which I built with MinGW. Here are the errors I'm getting: H:\ovgl\ovgl...\dependencies\Assimp\lib\libassimp.a(BlenderLoader.cpp.obj):BlenderLoader.cpp:(.text+0xd91): undefined reference to…
SteveDeFacto
  • 1,317
  • 4
  • 19
  • 35
17
votes
2 answers

Can I build a shared library by linking static libraries?

I have a bunch of static libraries (*.a), and I want to build a shared library (*.so) to link against those static libraries (*.a). How can I do so in gcc/g++?
flyingbin
  • 1,097
  • 2
  • 11
  • 28
17
votes
2 answers

IOS Static Library Product is always red

I've been struggling with this for a few days now. When I create a new Static Library project under IOS in XCode 4 I am running into an issue. With or without adding files as headers or to be compiled I am able to successfully build but the .a file…
Phil
  • 521
  • 1
  • 5
  • 14
17
votes
3 answers

Building static libraries on Mac using CMake and GCC?

Greetings all, I have a static library which I later link with my application. My development environment is CMake, GCC (Linux, Mac), MinGW (Windows). I can compile the static library without any problem on Linux and Windows. (I can even build…
Ashika Umanga Umagiliya
  • 8,988
  • 28
  • 102
  • 185
17
votes
2 answers

Xcode -- get force_load to work with relative paths

Some libraries require the -all_load linker flag when linking to an Xcode project. However, this leads to a linker error if there are symbol conflicts among libraries. The solution is to use -force_load, which effectively lets you use -all_load on…
William Jockusch
  • 26,513
  • 49
  • 182
  • 323
17
votes
2 answers

Singleton class in a static library

Suppose I have a singleton class S in a static library, this could be linked with the other dynamic libraries D1 D2 D3, So from what I understand the class S will have a separate instance in each D1, D2 and D3 and this would be true even if it is…
tejas
  • 1,795
  • 1
  • 16
  • 34
17
votes
1 answer

gcc - A static library with undefined symbols?

I'm trying to build a project using a static library, so that the binary can be used even if the library isn't installed. However, I get lots of errors about undefined symbols when I try to do so. Looking at the library, I see it has tons of…
SRobertJames
  • 8,210
  • 14
  • 60
  • 107