1

I got a project that uses Cmake and has a configuration to create a shared library. This project has some external dependencies (like zlib, etc). Generating shared library and linking against it would require not only providing dll generated by the project, but also dlls for all dependancies (since the library itself is linked against other libraries).

I'm wondering if it's possible to create a single dll of that project, that would have statically linked all dependencies into it. I tried creating an OBJECT library and using it to create a SHARED library with Cmake, but had no luck with this approach. Is this can be achieved?

Unfortunately static linking of the whole library is not an option due to licensing issues and I'd like to avoid attaching 10 dlls to the application package. I need that only for Windows.

liew
  • 69
  • 1
  • 9
  • You can not reasonably merge DLLs with any tool since they are not really code at that point and cross-dependencies would be a bitch if you tried to do it at byte-level. Without access to the code or static libraries for all the dependencies, you're completely out of luck. CMake and Visual Studio have nothing to do with it. – utopia Aug 11 '17 at 13:16
  • The question has nothing to do with cmake, because cmake doesn't really do anything with the libraries. Your other tools do. Please edit the question to make it unrelated to cmake. – Kuba hasn't forgotten Monica Aug 11 '17 at 13:59
  • @utopia Of course you can do exactly what the dynamic linker does, but simply ahead of time. I'm not aware of any tools that do that, though, so it'd be a case of roll-your-own. – Kuba hasn't forgotten Monica Aug 11 '17 at 14:01
  • @utopia thanks. I got access to the source code and to static libraries for all dependencies. I just wanted to merge all of these libraries into single dll (`add_library(project_name SHARED ...`) – liew Aug 11 '17 at 16:00
  • @KubaOber the project is built with cmake and there is similar technique described: https://stackoverflow.com/questions/11429055/cmake-how-create-a-single-shared-library-from-all-static-libraries-of-subprojec The only problem with it is that it uses `--export-all-symbols` which has no simple alternative on MSVC (`/WHOLEARCHIVE` does not work) – liew Aug 11 '17 at 16:02
  • The answer you link to has nothing to do with dynamic libraries! And again - that you use cmake is irrelevant. As soon as you find a tool, any tool, that can pre-link DLLs together, you can then use it with any build system. Adding custom tools to cmake is fairly easy. – Kuba hasn't forgotten Monica Aug 11 '17 at 18:03

0 Answers0