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

Android: Linking to prebuilt static libraries

I have compiled some static and shared libraries for Android. Specifically, I have the libraries libcoinblas.a libcoinlapack.a libcoinmetis.a libcoinmumps.a libipopt.a libcoinblas.so libcoinlapack.so libcoinmetis.so libcoinmumps.so …
bremen_matt
  • 6,902
  • 7
  • 42
  • 90
12
votes
1 answer

How to compile static .lib library for Windows in Linux or Macos

I am searching way to compile static library for Windows in Linux or Macos, there seems to be cross compiler to generate .a library for Windows like this one, but that is not what I want, what I want is a .lib static library file for Windows,…
Ryan
  • 800
  • 1
  • 13
  • 27
12
votes
2 answers

How can I look inside a Linux .so or .a object and see what functions they contain?

The linker can presumably do this, so is there a command-line tool to list functions in object files and tell me the names of functions and their signatures?
interstar
  • 26,048
  • 36
  • 112
  • 180
12
votes
3 answers

What happens to static variables when libraries are statically linked

Let's say I have library (A) implementing the singleton pattern (it has a static variable in its implementation). (A) library is compiled as a static library. Now, let's say I have in my probject: (B), another static library linking statically with…
jpo38
  • 20,821
  • 10
  • 70
  • 151
12
votes
4 answers

What are the pro and cons of statically linking a library?

I want to release an application I developed as a hobby both for Linux and Windows. This application depends on boost (and possibly other libraries). The norm for this kind of application (a chess engine) is to provide only an executable file and…
Mathieu Pagé
  • 10,764
  • 13
  • 48
  • 71
12
votes
4 answers

static library implementation vs including source code implementation

What are the general differences between compiling a program as a static library vs. including the source code into the program? i.e. A program with functions that is compiled as a static library (.lib) and linked into the program vs A program with…
user3647412
  • 129
  • 1
  • 5
12
votes
4 answers

Hiding symbol names in library

I want to hide symbol names which are not relevant to the end user and make visible only APIs in my shared or static library. I have a simple code like: int f_b1(){ return 21 ; } int f_b3(){ return f_b1() ; } I applied the all methods stated here…
mustafa.yavuz
  • 1,274
  • 2
  • 21
  • 40
12
votes
2 answers

Convert a Static Library to a Shared Library (create libsome.so from libsome.a): where's my symbols?

the title of this question is an exact dupe, but the answers in that question don't help me. I have a bunch of object files packed in a static library: % g++ -std=c++98 -fpic -g -O1 -c -o foo.o foo.cpp % g++ -std=c++98 -fpic -g -O1 -c -o bar.o…
just somebody
  • 18,602
  • 6
  • 51
  • 60
12
votes
6 answers

What is proper naming convention for MSVC dlls, static libraries and import libraries

What is standard or "most-popular" naming convention for MSVC library builds. For example, for following platforms library foo has these conventions: Linux/gcc: shared: libfoo.so import: --- static: libfoo.a Cygwin/gcc: shared: cygfoo.dll import:…
Artyom
  • 31,019
  • 21
  • 127
  • 215
12
votes
6 answers

How do I build OpenSSL statically linked against Windows runtime?

I'm working on a C++ application for Windows that uses OpenSSL 1.0.1e library. I'm on Visual Studio 2008. For portability reasons my application is statically linked against runtime libraries (/MT and /MTd options). And I don't ship runtime libs…
user2724991
  • 121
  • 1
  • 2
  • 6
12
votes
3 answers

Why does C# not have C++ style static libraries?

Lately I've been working on a few little .NET applications that share some common code. The code has some interfaces introduced to abstract away I/O calls for unit testing. I wanted the applications to be standalone EXEs with no external…
user1333
12
votes
4 answers

Is an executable built differently if linked against a library that's not used?

Apart from a longer compile time, is there any downside to linking against an unused library? for example, is there any difference in the executable of a program that is compiled one of two ways: g++ -o main main.cpp g++ -o main main.cpp -llib1…
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
12
votes
3 answers

Makefile for a library

I have to run these 4 commands on the terminal each time I want to execute the program using libraries. The lines are cc -m32 -c mylib.c ar -rcs libmylib.a mylib.o cc -m32 -c prog.c cc -m32 prog.o -L. -lmylib ./a.out How do I make a makefile for…
Aakash Anuj
  • 3,773
  • 7
  • 35
  • 47
12
votes
3 answers

linking to a static 0MQ library in VS

This may be a Visual Studio question more than anything else... I'm trying to build a 0MQ C++ example using VS10 and ZeroMQ 2.2.0. I downloaded the windows sources and tried to follow these instructions in order to build 0MQ statically.…
Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359
11
votes
3 answers

Why doesn't a C++ static library project have linker settings?

Revealing my ignorance: Why doesn't a static library project (in Visual Studio in my case) have linker settings in the project properties page? I thought "linking" was kind of a big deal re: libraries, but apparently I fundamentally misunderstand…
vargonian
  • 3,064
  • 3
  • 27
  • 36