Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting stack size in cmake with gcc

I am building a C++ project on Linux using gcc 9.2 and cmake 3.15, and I need to increase the default stack size. I found many answers before, but none of them seems to work

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--stack,1000000")
message(${CMAKE_CXX_COMPILER_ID})
message(${CMAKE_EXE_LINKER_FLAGS})

It gives an error:

/usr/bin/ld: unrecognized option '--stack'
/usr/bin/ld: use the --help option for usage information

I can see the argument is indeed is passed in the cmake output:

GNU
-Wl,--stack,1000000

And this following flag doesn't seems to exist at all.

set(CMAKE_CXX_STACK_SIZE 1000000)
like image 782
sz ppeter Avatar asked Dec 04 '25 03:12

sz ppeter


1 Answers

Solved. Thanks for @squareskittles 's comment. It should be:

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,stack-size=1000000")
like image 189
sz ppeter Avatar answered Dec 06 '25 16:12

sz ppeter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!