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
74
votes
5 answers

Android Studio : Missing Strip Tool

I am constantly getting this warning while building my android studio code using terminal command gradle clean assembleRelease: Unable to strip library 'lib.so' due to missing strip tool for ABI 'ARMEABI'. Packaging it as is. Please help me on how…
Sanket B
  • 1,070
  • 1
  • 9
  • 23
73
votes
5 answers

c++ undefined references with static library

I'm trying to make a static library from a class but when trying to use it, I always get errors with undefined references on anything. The way I proceeded was creating the object file like g++ -c myClass.cpp -o myClass.o and then packing it with…
Pyjong
  • 3,095
  • 4
  • 32
  • 50
73
votes
5 answers

CMAKE - How to properly copy static library's header file into /usr/include?

I'm getting into CMAKE usage with C and actually I'm creating two very small static libraries. My goal is: The libraries are compiled and linked into *.a files. [THIS WORKS] Then I wish to copy that *.a files into /usr/local/lib [THIS ALSO…
Miroslav Mares
  • 2,292
  • 3
  • 22
  • 27
72
votes
5 answers

ld linker question: the --whole-archive option

The only real use of the --whole-archive linker option that I have seen is in creating shared libraries from static ones. Recently I came across Makefile(s) which always use this option when linking with in house static libraries. This of course…
jasmeet
72
votes
1 answer

Why are LIB files beasts of such a duplicitous nature?

I'm trying to understand this LIB file business on Microsoft Windows, and I've just made a discovery that will - I hope - dispel the confusion that hitherto has prevented me from getting a clear grasp of the issue. To wit, LIB files are not the one…
Lumi
  • 14,775
  • 8
  • 59
  • 92
71
votes
5 answers

Contents of a static library

I have a static library, say mystaticlib.a. I want to see its contents, such as the number of object files inside it. How can I do this on gcc?
Prasoon Saurav
  • 91,295
  • 49
  • 239
  • 345
70
votes
5 answers

Convert a Static Library to a Shared Library?

I have a third-party library which consists mainly of a large number of static (.a) library files. I can compile this into a single .a library file, but I really need it to be a single .so shared library file. Is there any way to convert a static…
Eli Courtwright
  • 186,300
  • 67
  • 213
  • 256
69
votes
7 answers

After update to Xcode 5 - ld: symbol(s) not found for architecture armv7 or armv7s linker error

I just updated my iPhone 4S software to iOS 7 Beta 2 while I was in the middle of putting the final touches on a new app (Phonegap).. not a good idea! After it was done Xcode didn't detect my iPhone so I installed Xcode 5 beta. After tinkering…
barney
  • 891
  • 1
  • 8
  • 12
67
votes
3 answers

What is the difference between .o, .a, and .so files?

I know .o are object files, .a are static libraries and .so are dynamic libraries? What is their physical significance? When can I use some and when not?
Utkarsh Srivastav
  • 3,105
  • 7
  • 34
  • 53
60
votes
5 answers

How to static link on OS X

I'm trying to link to a static library on OS X. I used the -static flag in the gcc command but I get the following error message: ld_classic: can't locate file for: -lcrt0.o collect2: ld returned 1 exit status I looked in the man pages and it…
Frank
59
votes
3 answers

How to apply -fvisibility option to symbols in static libraries?

I have a shared library project that is built from 4 static libraries (.a) and one object (.o) file. I am trying to add the -fvisibility=hidden option to restrict symbols in the output to only those that I mark in the source with an…
Steve Fallows
  • 6,274
  • 5
  • 47
  • 67
58
votes
7 answers

Combining several static libraries into one using CMake

I have a very similar problem to one described on the cmake mailing list where we have a project dependent on many static libraries (all built from source in individual submodules, each with their own CMakeLists.txt describing the build process for…
learnvst
  • 15,455
  • 16
  • 74
  • 121
51
votes
4 answers

Combine static libraries on Apple

I tried the approach in this question, but it seems the linux version of ar is not the same as the mac version since I failed to combine the object files again. What I basically want to do is is merge another static library into my Xcode static…
user187676
51
votes
2 answers

Why does GCC create a shared object instead of an executable binary according to file?

I have a library I am building. All of my objects compile and link successively when I run either one of: ar rcs lib/libryftts.a $^ gcc -shared $^ -o lib/libryftts.so in my Makefile. I also am able to successfully install them into…
49
votes
2 answers

OpenCV as a static library (cmake options)

I want to use OpenCV library in an embedded system and I need to compile my project using OpenCV as a static library. How can I create the library using cmake options ?
Jorge Vega Sánchez
  • 7,430
  • 14
  • 55
  • 77