Questions tagged [static-linking]

A static library or statically-linked library is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable. This executable and the process of compiling it are both known as a static build of the program.

1772 questions
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
16
votes
2 answers

Why would it be impossible to fully statically link an application?

I'm trying to compile a statically linked binary with GCC and I'm getting warning messages like: warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking I don't…
dsimcha
  • 67,514
  • 53
  • 213
  • 334
16
votes
5 answers

In visual studio how to include all .libs in a folder

I am trying to build a project with another project. There are a lot of libs in there and I am not sure where the required unreferenced symbols are present. Is there a way I can include all the .lib files while compiling? I have given the lib…
AMM
  • 17,130
  • 24
  • 65
  • 77
16
votes
6 answers

C and C++ static linking: just a copy?

When someone statically links a .lib, will the linker copy the whole contents of lib into the final executable or just the functions used in the object files?
George
  • 385
  • 3
  • 12
16
votes
1 answer

How do I include only used symbols when statically linking with gcc?

I'm deploying a small program compiled with gcc, 4.3.2-1.1 (Debian). This program will be deployed on virtual machine templates ranging from Debain 5 to bleeding edge Fedora, Ubuntu, Slackware, Arch and others. The program depends on some symbols…
Tim Post
  • 33,371
  • 15
  • 110
  • 174
16
votes
4 answers

Is it possible to identify the library that correspond to certain header files?

Suppose we have several header and library files in the same directory. If I don't know which library I should link against, can I programmatically determine which library must be used. Lets say I tried to compile my code, and the linker complained…
user6274708
16
votes
5 answers

How to use pkg-config to link a library statically

I'd like to link libpng found by pkg-config statically. pkg-config --libs --static libpng outputs -L/usr/local/Cellar/libpng/1.6.15/lib -lpng16 -lz I have both libpng16.a libpng16.dylib in that directory, and if I use these flags the library gets…
Kornel
  • 97,764
  • 37
  • 219
  • 309
16
votes
1 answer

How to add static libraries inside a C++ project with Xcode

I'm developing a C++ project by using Xcode 4.6.1 as IDE. Now, I'd like to add a static library mylib.a and the related header mylib.h. I read about this solution, but it doesn't work (while clicking on Target Dependencies, the box is still…
vdenotaris
  • 13,297
  • 26
  • 81
  • 132
16
votes
2 answers

Link glibc statically but some other library dynamically with GCC

I need to statically link glibc to my project, because the target platform supports only a very old one ( but it works with statically linked glibc from my toolchain, I have checked it) Unfortunately, this application has to make use of pthread…
nkdm
  • 1,220
  • 1
  • 11
  • 26
16
votes
1 answer

Statically link GMP to an Haskell application using GHC (+ LLVM)

How can I drop dynamic dependency on libgmp and go from this: linux-vdso.so.1 => (0x00007fffdccb1000) libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007fb01afc1000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6…
Cetin Sert
  • 4,497
  • 5
  • 38
  • 76
14
votes
2 answers

Why isn't static linking used more?

I understand the benefits of dynamic linking (old code can take advantage of library upgrades automatically, it's more space efficient), but it definitely has downsides, especially in the heterogeneous Linux ecosystem. It makes it difficult to…
dsimcha
  • 67,514
  • 53
  • 213
  • 334
14
votes
3 answers

Combining static libraries

Suppose I have three C static libraries say libColor.a which depends on *libRGB.*a which in turn depends on libPixel.a . The library libColor.a is said to depend on library libRGB.a since there are some references in libColor.a to some of symbols…
AIB
  • 5,894
  • 8
  • 30
  • 36
14
votes
1 answer

What's the difference between "statically linked" and "not a dynamic executable" from Linux ldd?

Consider this AMD64 assembly program: .globl _start _start: xorl %edi, %edi movl $60, %eax syscall If I compile that with gcc -nostdlib and run ldd a.out, I get this: statically linked If I instead compile that with gcc -static…
14
votes
3 answers

How to compile a static musl binary of a Rust project with native dependencies?

I have a project with dependencies on Hyper and Diesel, and because of that, on native libraries OpenSSL and libpq. The project builds on nightly Rust because it uses compiler plugins. My current attempt is to build on a Docker container. I have the…
GolDDranks
  • 3,272
  • 4
  • 22
  • 30
14
votes
2 answers

How to force use of static library over shared?

In my SConscript I have the following line: Program("xtest", Split("main.cpp"), LIBS="mylib fltk Xft Xinerama Xext X11 m") How do I get scons to use mylib.a instead of mylib.so, while linking dynamically with the other libraries? EDIT: Looking to…
codehero
  • 157
  • 1
  • 1
  • 8