r/cpp • u/wiseneddustmite • May 30 '26
miniaudio compile times
i found this library called miniaudio, however instead of having precompiled dll files, its just the header and then the c file that really only includes the header, the header file has all of the definitions and declarations of everything in the library, it makes the compile times take a lot of time, can i compile the header file to a dll the c file is literally just:
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio/miniaudio.h"and the header file is like 4 megabytes
edit: nvm i just had to precompile the miniaudio.c file with -c first and it has a shorter compile time
13
Upvotes
18
u/kisielk May 30 '26
The whole point of the way they have it set up is so that the implementation is only compiled once, in the .c file. In your own code, you just include miniaudio.h, without the define. That will only give you the declarations, like a regular header, and not need to compile the implementation.
7
u/_Noreturn May 30 '26
You can preprocess out the IMPL so you don't have to parse it. I do not think the .h file without the impl part is huge
4
u/FirmSupermarket6933 May 30 '26
You can create separate file, e.g. miniaudio.c with define and include (and OFC remove that define from previous place). What do next is depend on how you build your project.
If you're using some build system, then just add one more source file to it.
If you're using unix and compile something like
cc main.cthen the easiest way is to precompile miniaudio and link with it:And on windows it should be something like this:
1
u/Excellent-Might-7264 May 30 '26
I use miniaudio, I put it in a separate translation unit as described by the other comments and never had issues.
I guess you use WIndows and Visual Studio? You can of course precompile a lib file and link to it statically if you do clean and rebuild a lot.
If it is the linker that takes time, something is wrong on your end, but you can of course build a DLL file and open it dynamically in runtime and do zero linking. Note, not linking to a DLL file in compile time but open the DLL in runtime. (Boilerplate like this to map function pointers to a DLL is a very easy task for any ai-agent. This is one of few parts they are better than humans at. Well, better than me at least who will always make a typo somewhere.)
3
u/SirLynix May 30 '26
Looks at the extra folder there's already a split version with a header and a source file.
0
u/Pleasant-Form-1093 May 30 '26
You can just precompile it to a .pch and use it for subsequent compilations (assuming you don't change the header itself frequently)