In OSX during C++ program compilation with g++ I use
g++
LD_FLAGS= -Wl,-stack_size,0x100000000
Consider using -fsplit-stack option https://gcc.gnu.org/wiki/SplitStacks
-fsplit-stack