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

Muhammad Arslan
  • 380
  • 1
  • 4
  • 10
TVA van Hesteren
  • 1,031
  • 3
  • 20
  • 47
  • 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 *.dll*s in your executable as __resources__. – CristiFati May 29 '17 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 – M.M May 29 '17 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). – CristiFati May 29 '17 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 – TVA van Hesteren May 29 '17 at 22:01
  • Here's an article about resources: [\[MSDN\]: Using Resources](https://msdn.microsoft.com/en-us/library/windows/desktop/ms648008(v=vs.85).aspx). This is _Ms_ specific. Basically, you embed your *.dll*s 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). – CristiFati May 30 '17 at 06:56
  • Did you manage to solve the problem? – CristiFati Jun 06 '17 at 09:23
  • @CristiFati, partly. The static linking succeeded however now I have no output on the console – TVA van Hesteren Jun 07 '17 at 09:46
  • So you statically compiled _OpenSSL_ and _cURL_? If you open your executable with [Dependency Walker](http://www.dependencywalker.com/) it doesn't depend on them? Anyway, I can't tell you why you don't have any output (as I don't know what/if you should have any kind of output). – CristiFati Jun 07 '17 at 09:50
  • @cristifati, yes. It seems my program pauses or something. The console isn't showing me output at all – TVA van Hesteren Jun 08 '17 at 08:37
  • But should it have any output? I mean isn't it waiting for user input for example? Could you post your code? ([\[SO\]: mcve](https://stackoverflow.com/help/mcve)) – CristiFati Jun 08 '17 at 08:52
  • @cristifati, no I also compiled and executed my app with an immediate output of count << "Hello!" Which also fails – TVA van Hesteren Jun 08 '17 at 11:31

1 Answers1

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).

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40