Fox1942
Fox1942

Reputation: 366

Why are some static libraries moved to /lib folder?

I was watching some tutorial videos connected to CMake and in one of them (link) the author installed a static library (.a) to user/local/lib. I am wondering what could be the benefit of putting it into there. As far as I know, after compiling, static libraries are packed into the final executable binary. According to me, only shared libraries should be moved into the /lib folder.

Or maybe, it is about avoiding recompilation during the build process in case of static libraries. Any help is appreciated.

Upvotes: 0

Views: 292

Answers (1)

zgyarmati
zgyarmati

Reputation: 1153

Generally the reason for installing static libraries is to be able to use it for compiling multiple executable binaries on the target system (even in different packages, so not necessarily from the same source tree). For this purpose, there are also static libraries which are packaged, and actually some packages ship both the .so and the .a files from the same lib (on my Debian system for example /usr/lib/x86_64-linux-gnu/{libpng16.a,libpng16.so} from the libpng-dev package), so it can be used both for statically and dynamically linked executables (which can be also a question of licensing). If in your project you don't want to install the static lib, but only using it during the compilation of the final executable, you can configure so in your CMakeLists.txt.

Upvotes: 1

Related Questions