0

For my C++ program I would like to statically link the following dlls' in my CodeBlocks setup with the MinGW GCC compiler:

  • libcurl-4.dll
  • libeay32.dll
  • ssleay32.dll

Yes, I know I can't statically link these DLLs since these are Dynamic Libraries. However, I can't figure out how to link the static libraries to overcome the required DLLs mentioned above.

I have tried many suggestions already, however, I still can't get it to work. At the moment I just redistribute the DLLs with my software, however, I would like to achieve to send off 1 .exe file.

Thanks for your helpful answers

11
  • You need to recompile cURL and OpenSSL to produce static libs, meaning that at the end there will be no .dll files just the .lib ones (and they will be a lot bigger than the ones you have now). However, regarding OpenSSL, I'm not sure if building static libs is still supported OOTB - instead of passing a simple parameter to configure, you'll probably have to tweak some of the build related files (Makefile, some .bat files...). Or of course, you could embed the .dlls in your executable as resources. Commented May 29, 2017 at 20:06
  • @CristiFati "Or of course, you could embed the .dlls in your executable as resources." - sounds like that is what OP is looking for, maybe you could expand on that Commented May 29, 2017 at 20:16
  • @M.M: If he/she confirms that it would work, I will write a solution (as it doesn't fit in a comment). Commented May 29, 2017 at 20:18
  • @CristiFati, How can I add the DLL's as resources? Will this deliver me 1 .exe file? If so, please tell me how I can implement this Commented May 29, 2017 at 22:01
  • Here's an article about resources: [MSDN]: Using Resources. This is Ms specific. Basically, you embed your .dlls in the executable, (and yes you only ship the executable,) but at runtime, at the beginning it will extract them (additional code is needed for that) and carry on with its job. However I didn't check how (if possible) to do it from MinGW (so I might have spoken too soon). Commented May 30, 2017 at 6:56

1 Answer 1

1

You either do shared linking using the lib*.dll.a files which makes your project depend on the corresponding .dll files, or you do static linking, in which case your project won't need the additional .dll files.

However, shared linking has the advantage that each .dll file takes care of it's own dependancies. With static linking you must not only link with static libraries your project depends on, but also the static libraries they depend on, and so on.

To make matters more difficult, MinGW/MinGW-w64 GCC is picky about the order in which you specify the static libraries.

If you have the static libraries on our system and they come with the .pc files you can use something like pkg-config --static --libs libcurl to list the static libraries you need to link with.

You can even specify that command in "Other linker options" on the "Linker settings" tab of the "Build options" of your Code::Blocks projects if you surround it with back-quotes: `pkg-config --static --libs libcurl`, provided pkg-config.exe is in the compiler path (or a path specified under "Additonal Paths" under the "Toolchain Executables" tab of the compiler settings).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.