0

I have a project in Code::Blocks which uses uses a dynamic library, and will use more in the future. I have set up the project correctly to use the library, and it compiles and runs perfectly fine.

However, I'm wondering if there is a way to compile a release version of the exe with the dlls needed in a folder alongside it. (I'd prefer not to hunt them each down and copy/paste them in.) I feel like I'm missing something, or going about it the wrong way.

Is there anyway to have Code::Blocks do this or a better way of obtaining an easy-to-distribute zipfile/project?

How could I use makefiles (cmake preferably, but any type compatible with Windows would be great) to accomplish this?

Numeri
  • 1,027
  • 4
  • 14
  • 32
  • Don´t know if CodeBlocks offers some "Hook" to insert scripts, but what about makefiles? – deviantfan Dec 27 '14 at 10:47
  • Frankly, I'm not very knowledgeable about makefiles—I wouldn't really know where to start other than googling "CMake tutorials"! (I've used CMake before, and have it installed on my computer.) – Numeri Dec 27 '14 at 13:12
  • Please note that `make` and `CMake` cannot be compared: the first is a tool calling the needed recipes to build something (and only if needed), while the latter can be seen as a "makefile generator": it does not actually build anything, besides the requested makefile/project file. – kebs Dec 30 '14 at 13:26

1 Answers1

1

CodeBlocks offers the ability to execute pre or post build things. Checkout menu "Project->Build options", and under the "Pre/Post build steps" tab, you can insert any shell command you want. For example:

enter image description here

When hitting F9, you will see:

-------------- Build: Release in aaa (compiler: GNU GCC Compiler)---------------
Target is up to date.
Running target post-build steps
echo "Hi"
Hi
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings (0 minutes, 0 seconds)

So you can add here any command you want to gather you files together, for example something like (using 7-zip):

7z a my_archive.zip myfile1.exe myfile2.dll readme.txt

Be advised that this will be executed at every build which is not something you might want: when compiling a minor change in program, you don't want to wait for the archive program. So maybe do this only in a special build target.

kebs
  • 6,387
  • 4
  • 41
  • 70
  • Thank you so much! I was hoping for a method to include every needed dll file, as there are (I believe) more dlls needed than what I have to put in the project folder. When I copy the entire project folder to another place and try to run the release exe, it fails. It says I'm missing a dll, but when I paste that and the other related dlls in, it complains I'm missing libgcc_s_sjlj-1.dll. Perhaps I asked the wrong question originally, but how can I fix this problem? An exe is rather useless if I have to use the IDE to run it. Thanks! – Numeri Dec 31 '14 at 13:15
  • Ok, so if I understand, the second part of the question is "How can I have a list of all the dll that are requested by my app ?" ?. I think [this answer](http://stackoverflow.com/a/475156/193789) will answer that. Let us know. – kebs Dec 31 '14 at 17:33
  • Thank you! So if I were to run depends.exe on my executable, I would then just trace down the dlls and paste them in the folder with my executable, after which I could distribute it as a zip file? – Numeri Jan 02 '15 at 16:49
  • Indeed, that's it. But you won't probably need to add them all, as some will be "Windows-standard" runtime libraries, thus available on the target machine. And remember you can accept answer if it fits your needs ;-) – kebs Jan 02 '15 at 19:20
  • Alright, thank you! I was just waiting until my question had been fully answered and I'll certainly accept yours now! – Numeri Jan 02 '15 at 21:06