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
2
votes
1 answer

static-libgcc and static-libstdc++ not working

I try to compile projects with -static -static-libgcc -static-libstdc++ in order to have libraries statically linked. However, exec is compiled with dynamically linked libraries. I try to reinstall gcc and g++ but it doesn't help. It's rather my…
galvanize
  • 537
  • 1
  • 5
  • 17
2
votes
1 answer

Distribution and Linking of C Header Files and Libraries

I am brand new to C programming (but not programming) and am trying to understand how libraries and header files work together, particularly with respect to packaging and distribution. After reading this excellent question and its answer, I…
smeeb
  • 27,777
  • 57
  • 250
  • 447
2
votes
1 answer

Third party C static library: Add -ffunction-sections -fdata-sections

I am in the situation to have a c static library (compiled with arm-gcc), which is provided by a third party. I have no possibility to (let the third party) re-compile the library. When investigating the library contents, i found that the gcc…
2
votes
1 answer

How to add to Interface builder classes in a static library, permanently?

I know the thread on Interface Builder can't see classes in a static library there add to InterfaceBuilder(IB) classes in static library, temporary. The way is drag & drop the header files(.h). It's working in one time booting the IB I wanna…
TopChul
  • 419
  • 2
  • 14
2
votes
1 answer

Compiling C Library for iOS 9 From Command Line, Xcode 7-beta 2

I am having trouble compiling a C library (gmp) for iOS 9 using the latest Xcode 7-beta clang. I am trying to produce bitcode to get all the warnings in Xcode to stop (and I would like to produce these libraries in bitcode). However, I can't even…
stack_tom
  • 950
  • 2
  • 9
  • 18
2
votes
2 answers

Compile Curl Visual Studio - unresolved external symbol

I need to use a static library of libcurl and I found this github rep that generate the libraries. Now, I'm trying to compile a simple piece of code that use curl using the static library, libcurl_a.lib, but without success. At first, I miss the…
hmiguel
  • 343
  • 1
  • 4
  • 16
2
votes
1 answer

Compile position-independent executable with statically linked library on 64 bit machine

When I try to compile with the following command-line: g++ code.cpp /usr/lib/x86_64-linux-gnu/libcrypto.a -ldl -Fpie -pie -o executable I get the following error message: /usr/bin/ld: /tmp/ccNHn5FA.o: Die Umlagerung von /tmp/ccNHn5FA.o: error…
Maximilian
  • 1,325
  • 2
  • 14
  • 35
2
votes
1 answer

prevent static library from being initialized

I have a class that I need to connect with a few other classes and libraries. One of these libs requires a webcam. Problem is that this requirement is done in a static (I suspect a constructor of a static) and this library is in binairy form so I…
Thijser
  • 2,625
  • 1
  • 36
  • 71
2
votes
1 answer

Can't link fat iOS static library

I recently downloaded a fat, iOS static library for the popular C library boost. All my attempts in coaxing Xcode to link it have failed. Things I have tried: Adding it to Link Binary With Libraries. Changing file type to Mach-O Object Code using…
Vatsal Manot
  • 17,695
  • 9
  • 44
  • 80
2
votes
2 answers

Determine .lib / .dll with header file

I have 3rd party library in my program. For example : #INCLUDE <3rdPartyHeaderA.h> #INCLUDE <3rdPartyHeaderB.h> int main(int argc, char** argv) { // some stuff } How do i know 3rdPartyHeaderA.h is using which particular .lib or .dll. I looked…
LOK CARD
  • 293
  • 2
  • 16
2
votes
1 answer

Static linking against non-binary libs

I want to make use of two libraries QCustomPlot and Eigen with Qt Creator on OS X. Both do not need to be installed and work fine if I just put them into my project folder and add them to the project. They do not have to be installed, "you can use…
Sharky Bamboozle
  • 1,066
  • 16
  • 28
2
votes
1 answer

Including STL in static libraries

I have created a static library with the files alien.h and alien.cpp below. That library is linked by the file user.cpp. If one removes the line with the comment, then the code compiles, links, and runs as expected. As it is, the library and the…
Hector
  • 2,464
  • 3
  • 19
  • 34
2
votes
2 answers

Why do I have to embed my libraries inside my applications binary for them to work?

So I followed this tutorial: http://locomoviles.com/ios-tutorials/create-ios-cocoa-touch-framework-using-xcode/ Everything went fine except when I went to run the program I got the following error: > dyld: Library not loaded: >…
FreaknBigPanda
  • 1,127
  • 12
  • 17
2
votes
0 answers

Visual Studio C++ - Library throwing an exception when included in a different project type

I have two projects, let's call them A and B. A builds to .dll and B builds to .exe. Both of them use my static library. They link to an exact same .lib file. A works fine. B, however, crashes with "Access violation writing location" at first point…
tomi.lee.jones
  • 1,563
  • 1
  • 15
  • 22
2
votes
0 answers

XCode: Use hosting projects preprocessor macros in framework

I am developing a static iOS library (that is compiled into a .a file). In the librarys code, I sometimes check if the framework is running in debug mode, as so: #ifdef DEBUG return YES; #else return NO; #endif The issue is, that when the…
BlackWolf
  • 5,239
  • 5
  • 33
  • 60