drogon
drogon copied to clipboard
How to compile a project fully statically?
How to achieve full static compilation of the project? The compiled executable file can be run in binary mode on other linux systems. (The operating environment does not need to install related dependencies)
You have to use the static libraries of all the dependencies (trantor, openssl, zlib, libpq and so on) and build drogon in static mode, even so, you need to ensure that the build system and the target system's lower-level libraries (for example, libc, libstdc++) are compatible, In conclusion, this is a difficult thing, so container technologies like docker are becoming more and more popular.
For arm64
you might benefit from:
FROM omrmohamed/drogon:archlinux
I also recommend using Docker Slim
您必须使用所有依赖项(trantor、openssl、zlib、libpq 等)的静态库并以静态模式构建 drogon,即使如此,您也需要确保构建系统和目标系统的低级库(比如libc、libstdc++)是兼容的,总而言之,这是一件很难的事情,所以像docker这样的容器技术越来越流行。
How to statically build the libraries that the project depends on, and try to ensure that the minimum dependencies are installed?
You have to use the static libraries of all the dependencies (trantor, openssl, zlib, libpq and so on) and build drogon in static mode, even so, you need to ensure that the build system and the target system's lower-level libraries (for example, libc, libstdc++) are compatible, In conclusion, this is a difficult thing, so container technologies like docker are becoming more and more popular.
How to statically build the libraries that the project depends on, and try to ensure that the minimum dependencies are installed?
For
arm64
you might benefit from:FROM omrmohamed/drogon:archlinux
I also recommend using Docker Slim
How can a statically compiled project run with the smallest volume capacity? Example: FROM scratch as runner?
I think you just:
FROM scratch
COPY static-binary /
ENTRYPOINT ["/static-binary"]
but I haven't compiled a drogon project statically before, although I would like to know the process if you managed to do this.
The other and easier way is to use a drogon base image with a compiler included and build with docker-slim.
The image I mentioned is about 2.6GB
for amd64
and 3GB
for arm64
(Crypto++ is included) docker-slim produces 50MB
images or 57MB
if I want a basic shell in the container and of course this depends on the project code size.
In case anyone is interested, the default instructions of drogon for installing the dependency packages will have some packages with both .so
and .a
files, and CMake prefers .so
if both exist.
The list of shared libraries drogon will link against using packages:
-
libjsoncpp.so
- This one has no.a
equivalent, you must build jsoncpp statically and install it with-DCMAKE_INSTALL_PREFIX:PATH=/usr
-
libcares.so
-
libuuid.so
-
libbrotlidec.so
-
libbrotlienc.so
-
libbrotlicommon.so
-
libz.so
These two may have also been linked, you can find out what shared libs are linked by opening the build/build.ninja
file if you are building with Ninja, or makefiles if you use Unix Makefiles, and search for \.so
or .so
:
-
libssl.so
-
libcrypto.so
My process for forcing the use of static libs in linking, is to have a bash file that removes these .so
files.
You can play it safer and rename these files to something else until CMake finishes writing build instructions, then after that rename them back to .so
. This allows CMake to only find .a
libs and links against these.
An even safer method is to run CMake, then edit your build instructions file (build/build.ninja
) and do a search and replace for .so
-> .a
.