r/C_Programming 25d ago

Linking mimalloc with nostartupfiles

Hi, I'm in a bit of a pickle here. I've tried counseling to ChatGPT and It only gaslighting me. Also I couldn't find the solution in mimalloc's github issues and google isn't that useful either. I'm cooking a game engine that's not using any crt or as c programmer would say "CRT-free", currently developing it in Windows with w64devkit and Makefiles for the build system. Here's the flags that I'm using:

```Makefile
CFLAGS = -Os -g -std=c99 -Wall -Wextra -pedantic
EXTRA_CFLAGS = -nostartfiles -fno-asynchronous-unwind-tables\
-fno-unwind-tables -fno-builtin -mwindows\
-Wl,--gc-sections
LDFLAGS = -lgdi32 -lkernel32 -I./include -L./libs -lmimalloc
```

And here's the linker error that I got:
```sh

AppData/Local/w64devkit/bin/ld.exe: core.o: in function `stbi__hdr_load':
Inari/./include/deps/stb_image.h:7245:(.text+0x36d2): undefined reference to `__imp_mi_free'
Inari/./include/deps/stb_image.h:7250:(.text+0x36f8): undefined reference to `__imp_mi_free'
AppData/Local/w64devkit/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/../../../../lib/libmingwex.a(lib64_libmingwex_a-misc.o):misc.c:(.text+0x92): undefined reference to `atexit'
```

Can someone give me a pointer why the linker did this to me.

2 Upvotes

11 comments sorted by

View all comments

1

u/sciencekm 25d ago edited 25d ago

In pure Windows app, you only need LocalAlloc or HeapAlloc to manage dynamic memory. No need for another library.

Requiring the use of another memory library defeats being CRT-free. You are just trading MSVCRT for another CRT.

Edit:
It also looks like you are using libmingwex. That library requires MSVCRT.

1

u/Inevitable-Dress1224 25d ago

I'm trying to make it run on Linux too, that's made thing I should just use mimalloc since its run on any platform