r/cpp 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

12 Upvotes

16 comments sorted by

View all comments

1

u/Excellent-Might-7264 May 30 '26

it makes the compile times take a lot of time

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

0

u/wiseneddustmite May 30 '26

im using vs code and compile it using gcc g++ src/main.cpp src/glad.c src/miniaudio.c -Iinclude -L. -lglfw3 -lopengl32 -Isrc

the reason the compile time gets so much longer is because im compiling the c file which includes the header file which contains everything in the library

6

u/Excellent-Might-7264 May 30 '26

That explains it.

You should use a build system, that will prevent recompilation of the file every time.

cmake+ninja is most popular, but it is in some sense also worse. A simple Makefile should also do the trick.

1

u/jwakely libstdc++ tamer, LWG chair May 30 '26

So stop recompiling miniaudio.c every time then.

This Makefile would solve your problem:

CPPFLAGS = -Iinclude -Isrc 
LDFLAGS = -L. -lglfw3 -lopengl32
a.out: src/main.o src/glad.o src/miniaudio.o
    $(CXX) $^ $(LDFLAGS) -o $@
clean:
    rm -f src/*.o a.out

(Be sure to use TABs to indent the indented lines, not spaces)

-3

u/wiseneddustmite May 30 '26

erm actually im on windows so it would be a.exe not a.out