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
23
votes
3 answers

Linking static library with JNI

Java versions prior Java 8 requires native code to be in a shared library, but I've read that with Java 8 it's possible to use static linked libraries with JNI. I have searched for examples but couldn't find any. How can I statically link a JNI…
22
votes
1 answer

How to build boost static libs?

This works, but doesn't build static versions of boost libraries (maybe i am wrong?) bjam --toolset=gcc --prefix=C:\boost_1_49_0-mingw install Trying to issue folloving command: bjam --toolset=gcc --prefix=C:\boost_1_49_0-mingw…
pavelkolodin
  • 2,859
  • 3
  • 31
  • 74
22
votes
2 answers

Compiling ghc with -fPIC support

I'm trying to install GHC with -fPIC support in Fedora. I've grabbed a source tarball since it seems no binary one has this. In Build.mk i've changed the quick build type to ifeq "$(BuildFlavour)" "quick" SRC_HC_OPTS = -H64m -O0 -fasm…
Phyx
  • 2,697
  • 1
  • 20
  • 35
22
votes
2 answers

Using static libraries with CocoaPods 1.5 no such module at import

With CocoaPods 1.5 released I am trying to migrate from having 10-15 dynamic pods in my projects to having them as static libraries instead, with the goal of speeding up my app start time. At this stage my simple (i.e., simplistic) attempt has been…
Franc
  • 351
  • 1
  • 3
  • 8
22
votes
1 answer

Create a static library with React dependency

I created a library that uses the native navigation controller to navigate through react and native screens. The library is written in Swift and contains some objective-c code to setup the React bridge etc. Currently I can distribute this library…
Mark Molina
  • 5,057
  • 8
  • 41
  • 69
22
votes
1 answer

How to implement "make install" in a Makefile?

So here's the repo I'm working with: https://github.com/Garuda1/unixlib I'd like to know where my compiled lib (unixlib.a) and where my header (unixlib.h) should be so as to be able to use the lib (under Linux-x86 or Linux-x86_64) simply by…
Garuda1
  • 331
  • 1
  • 2
  • 3
22
votes
6 answers

Prevent duplicate symbols when building static library with Cocoapods

While I've seen many questions dealing with Cocoapods and static libraries, most of them seem to assume you'll eventually have a single workspace with your static library and end target app. In my scenario, I am building a static library. More…
Erik Kerber
  • 5,646
  • 7
  • 38
  • 56
22
votes
2 answers

Add static library to podspec

My podspec requires a static library (OpenSSL). For convenience, I'm shipping the library with the pod. The static library contains: Binaries: MyPod/openssl/bin/libcrypto.a and MyPod/openssl/bin/libsll.a Headers:…
hpique
  • 119,096
  • 131
  • 338
  • 476
22
votes
4 answers

How can I inspect a static library to see if the debug symbols are being exported?

I have a static library I'm building in debug mode, but when I step into it I still get disassembly. I want to know how to use nm or another tool to ensure that the debug symbols are not being stripped.
Spilly
  • 1,069
  • 2
  • 9
  • 16
22
votes
1 answer

What's the difference between C/C++ Library and STL C++ Library in XCode?

I'm trying to create a C++ library in Xcode and I'm not sure whether to choose the C/C++ Library or the STL C++ Library option? I noticed that the STL C++ Library option doesn't let you create a static library and force you to create a dynamic…
Tony
  • 36,591
  • 10
  • 48
  • 83
21
votes
2 answers

How to use function from static library if I don't have header file

Is it a way to use function from static lib, if I don't have header file, only *.a file, but I know function signature?
Hate
  • 1,185
  • 3
  • 12
  • 24
21
votes
1 answer

Create shared library from cpp files and static library with g++

Just like title says, I want to create shared library from three cpp files and with some static library. Basicly I want to do this g++ libProject.so file1.cpp file2.cpp file3.cpp -I /usr/local/include -L /usr/local/lib -lAlgatorc This is my…
golobitch
  • 1,466
  • 3
  • 19
  • 38
21
votes
3 answers

Release mode static library much larger than debug mode version

today i found out that the compiled static library i'm working on is much larger in Release mode than in Debug. I found it very surprising, since most of the time the exact opposite happens (as far as i can tell). The size in debug mode is slightly…
PeterK
  • 6,287
  • 5
  • 50
  • 86
21
votes
7 answers

How to convert a dynamic dll to static lib?

I write a program helloworld.exe; it depends on a.dll. I don't have the source code of the a.dll, which is a dynamic dll. How can i change it to static library, so I can link it into helloworld.exe?
xufan
  • 392
  • 1
  • 5
  • 18
21
votes
2 answers

Link error: "Cannot find -ltinfo" on Ubuntu 12.04 on a 32-bit arm processor

I get the following link error when I'm compiling a small function using ncurses for an Ubuntu 12.04 running on arm. The error is arm-linux-gnueabihf/bin/ld: cannot find -ltinfo A lot of hints are floating around on what to install, but I can't…
Henrik
  • 586
  • 1
  • 4
  • 10