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
502
votes
19 answers

When to use dynamic vs. static libraries

When creating a class library in C++, you can choose between dynamic (.dll, .so) and static (.lib, .a) libraries. What is the difference between them and when is it appropriate to use which?
Morten Christiansen
  • 19,002
  • 22
  • 69
  • 94
489
votes
16 answers

Static linking vs dynamic linking

Are there any compelling performance reasons to choose static linking over dynamic linking or vice versa in certain situations? I've heard or read the following, but I don't know enough on the subject to vouch for its veracity. 1) The difference in…
Eloff
  • 20,828
  • 17
  • 83
  • 112
294
votes
5 answers

What do 'statically linked' and 'dynamically linked' mean?

I often hear the terms 'statically linked' and 'dynamically linked', often in reference to code written in C, C++ or C#. What are they, what exactly are they talking about, and what are they linking?
UnkwnTech
  • 88,102
  • 65
  • 184
  • 229
164
votes
5 answers

Define static method in source-file with declaration in header-file in C++

I am having a little trouble working with static methods in C++ Example .h: class IC_Utility { public: IC_Utility(); ~IC_Utility(); std::string CP_PStringToString( const unsigned char *outString ); void CP_StringToPString(…
ABV
  • 1,645
  • 2
  • 11
  • 5
137
votes
2 answers

Small Haskell program compiled with GHC into huge binary

Even trivially small Haskell programs turn into gigantic executables. I've written a small program, that was compiled (with GHC) to the binary with the size extending 7 MB! What can cause even a small Haskell program to be compiled to the huge…
user181351
120
votes
5 answers

iOS Static vs Dynamic frameworks clarifications

I have to admit that with the release of iOS 8 I am a bit confused about dynamic and static frameworks in iOS. I am looking for a way to distribute a library that I created, and I need to support iOS 7 and above. (Note: This will be a proprietary…
csotiriou
  • 5,653
  • 5
  • 36
  • 45
110
votes
21 answers

Why do I get iOS linker errors with my static libraries?

I have a problem with linking my mixed language framework to a project. I create a framework with Swift and Objective-C classes. The main logic was stored in the Swift file. For example the class with a method that calls NSLog("Swift log was…
89
votes
1 answer

GPL/LGPL and Static Linking

I have read on the web that following combination exists : Proprietary Source code + GPL Source code - > GPL Source code ( All code has to be released under GPL) Proprietary Source code + LGPL Source code - > Proprietary Source code ( All code…
Raulp
  • 7,758
  • 20
  • 93
  • 155
86
votes
3 answers

Why is statically linking glibc discouraged?

Most of the sources online state that you can statically link glibc, but discourage from doing so; e.g. centos package repo: The glibc-static package contains the C library static libraries for -static linking. You don't need these, unless you…
pzelasko
  • 2,082
  • 1
  • 16
  • 24
79
votes
2 answers

How to generate statically linked executables?

I am trying to create a static executable with Rust. I am not trying to statically link a particular library, I am trying to create a executable which does not use dynamic linking at all. I have the following (otherwise working) test: $ cat…
David X
  • 3,998
  • 3
  • 29
  • 32
76
votes
6 answers

Linux static linking is dead?

In fact, -static gcc flag on Linux doesn't work now. Let me cite from the GNU libc FAQ: 2.22. Even statically linked programs need some shared libraries which is not acceptable for me. What can I do? {AJ} NSS (for details just type `info libc…
Shcheklein
  • 5,979
  • 7
  • 44
  • 53
67
votes
2 answers

Why does gcc not implicitly supply the -fPIC flag when compiling static libraries on x86_64

I've had numerous problems compiling shared objects that link statically against static libraries. This problem only shows up on x84_64 platforms. When doing the same compilation work on x86_32 I do not have any problems. Perhaps this is a OS…
Hassan Syed
  • 20,075
  • 11
  • 87
  • 171
66
votes
3 answers

#pragma comment(lib, "xxx.lib") equivalent under Linux?

I have a static library file called libunp.a, I do know I could use gcc -lunp xx to link to the library. I could use #pragma comment(lib,"xxx.lib") to tell the Microsoft C/C++ compiler to include the library; how could I do it under Linux/GCC?
Jichao
  • 40,341
  • 47
  • 125
  • 198
64
votes
10 answers

how to do static linking of libwinpthread-1.dll in mingw?

I use mingw from here: http://sourceforge.net/projects/mingwbuilds/files/host-windows/releases/4.7.2/32-bit/threads-posix/sjlj/x32-4.7.2-release-posix-sjlj-rev2.7z/download And I've sucessfully managed to link statically libstdc++-6.dll and…
rsk82
  • 28,217
  • 50
  • 150
  • 240
60
votes
2 answers

iOS is it a static or a dynamic framework?

This might sound like a silly question but If you have a thirdParty.framework file, can you tell if it's static or dynamic? I mean, do they look different if you look inside?
Hadi tavakoli
  • 1,267
  • 2
  • 16
  • 30
1
2 3
99 100