Stack overflow when compiling on Windows 10

Sure. But it depends on the linker. For the msvc toolchain it's something like /STACK:8000000 which will set the stack to 8 megabytes. For the gnu toolchain it's --stack 8000000 (took me awhile to find where that's documented).

Setting this in Rust is a bit awkward. You need to create a folder in the root of your project directory called ".cargo" and then add a file to it called "config.toml". In that file you can set custom linker options:

# 64 bit MSVC
[target.x86_64-pc-windows-msvc]
rustflags = [
	"-C", "link-arg=/STACK:8000000"
]

# 64 bit Mingw
[target.x86_64-pc-windows-gnu]
rustflags = [
    "-C", "link-arg=-Wl,--stack,8000000"
]

edit: changed mingw linker format because mingw makes it surprisingly hard to pass linker arguments.

6 Likes