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.
Questions tagged [static-linking]
1772 questions
28
votes
2 answers
C++ global variable not initialized when linked through static libraries, but OK when compiled with source
I have created a system that automatically registers function objects (functors) into a map based on the constructor of an global instance.
In each cpp file that defines the functor, there's a global instance of the registrar class instance to…

t.g.
- 1,719
- 2
- 14
- 25
28
votes
4 answers
How to link a .DLL statically?
We have a (pure native C++) .DLL that is build by VS. As clients we have some native C++ applications and a .Net-Wrapper around this DLL written in C++/CLI. Finally there are some client applications for the .Net-Wrapper written in C#.
My problem is…

mmmmmmmm
- 15,269
- 2
- 30
- 55
28
votes
1 answer
MinGW creating dll.a files ? What type of library files are those?
I am fairly familiar with Windows and Linux libraries compilation but as for today when I have seen MinGW on my Windows machine threw out dll.a and .a files after OpenCV compilation I have started to seriously start thinking.
These are my \lib…

Patryk
- 22,602
- 44
- 128
- 244
27
votes
2 answers
How to compile Haskell to a static library?
Hey,
I'm learning Haskell and I'm interested in using it to make static libraries for using in Python and probably C. After some googling I found out how to get GHC to output a shared object, but it dynamically depends on GHC`s libraries.
The…

kuratkull
- 327
- 3
- 9
26
votes
1 answer
PDB 'vc100.pdb' was not found with
I have downloaded the FreeImage source code and done a static build myself for X64 MT DLL.
Everything works fine, except when I use link in the freeimage.lib file I get a lot of annoying linker warnings which I don't quite understand the cause…

ronag
- 49,529
- 25
- 126
- 221
26
votes
3 answers
Create a static Haskell Linux executable
It's not often two things I love so much come together to cause me so much annoyance (besides my kids). I've written a Haskell program at work that uses libraries like text, xml-enumerator, attoparsec-text, etc. I have it working properly on my…

Michael Snoyman
- 31,100
- 3
- 48
- 77
26
votes
3 answers
How to build a C program using a custom version of glibc and static linking?
I have built glibc 2.14 and installed it in directory ~/GLIBC/glibc_install. Now I want to build and run programs using this C library instead of my system's default C library.
To be sure that I was using my custom glibc, I added a call to puts…

Amittai Aviram
- 2,270
- 3
- 25
- 32
25
votes
2 answers
CMake: Linking statically against libgcc and libstdc++ into a shared library
Problem:
I am having difficulties linking glibcc/glibc++ into a shared library using CMake and GCC4.9 on my Ubuntu 16.04 installation.
Additional conditions:
Loading the shared library gives a problem om the Red Hat production environment(where I…

DA--
- 723
- 1
- 8
- 20
25
votes
7 answers
How do I tell cmake I want my project to link libraries statically?
I'm trying to build an OpenCV-based project using CMake, running on Linux. So far my CMakeLists.txt files looks something like
FIND_PACKAGE (OpenCV REQUIRED)
...
TARGET_LINK_LIBRARIES (my-executable ${OpenCV_LIBS})
but this results in dynamically…

agnul
- 12,608
- 14
- 63
- 85
25
votes
3 answers
Can Clang compile code with GCC compiled .a libs?
I have my project currently compiling under gcc. It uses Boost, ZeroMQ as static .a libraries and some .so libraries like SDL. I want to go clang all the way but not right now. I wonder if it is possible to compile code that uses .a and .so…

DuckQueen
- 772
- 10
- 62
- 134
25
votes
6 answers
Why create a .a file from .o for static linking?
Consider this code:
one.c:
#include
int one() {
printf("one!\n");
return 1;
}
two.c:
#include
int two() {
printf("two!\n");
return 2;
}
prog.c
#include
int one();
int two();
int main(int argc, char…

poundifdef
- 18,726
- 23
- 95
- 134
24
votes
4 answers
Proper way to link a static library using GCC
Why is it that some static libraries (lib*.a) can be linked in the same way that shared libraries (lib*.so) are linked (ld -l switch), but some can not?
I had always been taught that all libraries, static or not, can be linked with -l..., however…

Nairou
- 3,585
- 5
- 29
- 47
24
votes
2 answers
How can I statically link standard library to my C++ program?
I'm using Code::Blocks IDE(v13.12) with GNU GCC Compiler.
I want to the linker to link static versions of required runtime libraries for my programs, how may I do this?
I already know that my executable size will increase. Would you please tell me…

AmRCPP
- 241
- 1
- 2
- 4
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…

chmod
- 278
- 1
- 2
- 7
23
votes
1 answer
Difference between linking OpenMP with -fopenmp and -lgomp
I've been struggling a weird problem the last few days. We create some libraries using GCC 4.8 which link some of their dependencies statically - eg. log4cplus or boost. For these libraries we have created Python bindings using boost-python.
Every…

duselbaer
- 935
- 2
- 6
- 10