0

I'm creating a GDScript wrapper library using tiny-dnn C++ library as base.

The issue is that tiny-dnn is header-only, and I have to include it in most of my library's .cpp files (after all, I'm creating a wrapper). This results in a compilation time of 1 minute/file and a binary of ~300MB.

As a "solution" I decided to put all my code (20 .cpp files) into a big file and include tiny-dnn just once. The compilation time rate stayed the same, but now I have only one file, and the binary size reduced to ~50MB. Based on this experiment, I guess that tiny-dnn is being copied over and over again as I include it.

I can continue my project using the "solution" above, but I'm still questioning: is there a way to keep the reduced binary size and the reduced compilation time, still have separate files and still use tiny-dnn?

By the way, I'm using Linux and compiling with g++, along with SCons.

  • 1
    While the compilation time issues makes sense, I don't see how you could have such drastically different binary sizes. While the intermediate object files might contain many duplicate symbols from inline functions, these should all be merged into one by the linker. The resulting binary should look roughly the same. You might want to have a compare the symbols in the final binaries for both cases. – walnut Mar 06 '20 at 04:31
  • Could it be that you're not linking the way you think you are? `ldd your_execuable` should show what dynamic linking you have. – Ted Lyngmo Mar 06 '20 at 05:30
  • When I read both of your comments I had the idea to play with my compile flags (that I copied from somewhere else) and I found out that using `-g` flag indiscriminately results in a much bigger binary file. By removing it I could reduce the binary to mere 6MB, either merging or not the files. I'm using `-O3` flag too, which makes the compilation two times slower in my case, but I'll trust @walnut and accept that I'll not be able to reduce this even more. I'm OK with the results, thanks for your help folks! – IceMage144 Mar 07 '20 at 00:12

0 Answers0