What are the pro and cons of statically linking a library?

I want to release an application I developed as a hobby both for Linux and Windows. This application depends on boost (and possibly other libraries). The norm for this kind of application (a chess engine) is to provide only an executable file and possibly some helper files.

I tough it would be a good idea to statically link the libraries so the executable would not have any dependencies. So the end user can just put the executable in a directory and start using it.

However, while doing some research online I found some negative comments about statically linking libraries, some even arguing that an application with statically linked libraries would be hardly portable, meaning that it would only run on my system of highly similar systems.

So what are the pros and cons of statically linking library?

I already know that the executable will be bigger. But I can't see why it would make my application less portable.


Pros: No dependencies.

Cons: Higher memory usage, as the OS can no longer use a shared copy of the library. If the library needs to be updated, your application needs to be rebuilt. This is doubly important for libraries that then have security fixes.

Of course, a bigger issue for portability is the lack of source code distribution.

Let's say the static library "A" you include has a dependency on function "B". If this dependency can't be fulfilled by the target system, then your program won't run.

But if you're using dynamic linking, the user could maybe install another version of library "A" that uses function "C" instead of "B", so it can run successfully.

If you link the libraries statically, unless you add the smarts to also check the user's system for the libraries you've linked, you're locking your application to use those versions of the libraries until you update your executable. Security holes happen, and updates happen. (For a chess engine there may not be too much issue, but who knows.)

With dynamically linked libraries, if the library say X, you have linked with is not available at the user system, your code crashes ungracefully leaving the end user wondering. Whereas, in the case of static libraries everything is fused into the executable, so a condition like above mayn't happen, the executable however will be very bulky.

The above problem in dynamically linked libraries can however, be eliminated by dynamic loading.

Need Your Help

get user info using access-token Ruby on rails

ruby-on-rails ruby-on-rails-4 omniauth

I have worked with omniauth using api-key ,api-secret pair . but what if I have the access token and I don't want to use key/secret to fetch user data . How can I do it for Facebook and Google+ . Any

Inserting HTML5 video using JavaScript for iPad

jquery video ipad html5

I am trying to insert a video into HTML using jQuery for iPad but all I see is a black screen. If I add the video tag directly to the HTML page all seems to work fine.