Skip to content
Advertisement

Deplying a C++ application on Linux- linking everything statically to simplify deployment?

I am building a C++ project from Github and want to deploy the code to a remote Linux machine. This is all new to me.

The project has a main.cpp, which includes the various headers/sources like a library.

The CMake outputs an executable (to represent main.cpp) AND a separate static library. The project also uses OpenSSL, which I have linked statically.

  1. I presume the OpenSSL functions are included within the static library? So when I deploy, I don’t need to copy-over or install any OpenSSL on the remote machine?

  2. Is it possible to modify the CMake so the application and the library are merged in to one file?

I am trying to make deployment as simple as copying over a single file, if this is possible.

Any additional advice/references are most-welcome.

UPDATE the CMake script:

JavaScript

Advertisement

Answer

ITNOA

I it is very helpful to make URL of your GitHub’s project, but I write some public notes about that

In generally in CMake for static linking your library to your executable, you can write simple like below (from official CMake example)

JavaScript

In above example your executable file is just work without needing .a library file and you can simple copy single file.

if you want to make all of thing static, you make sure all dependencies make static link to your project, like CMake: how to produce binaries “as static as possible”

if you want to prevent library creation, Probably in your CMake file, you can find add_library command, and add_executable command. you can remove add_library command and add all sources to add_executable command.

for example add_executable(a.out main.cpp lib.cpp)

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement