Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to GCC compile without _alloca?

For some reason, I should use gcc to compile a C file, then link against Visual C++ 2008 project.

(I used the current latest gcc version: cygwin gcc 4.3.4 20090804.)

But there is one problem: gcc always allocate a big array with _alloca,

and VC linker can't resolve the symbol __alloca.

for example,

int func()
{
    int big[10240];
    ....
}

this code makes the _alloca dependency although I didn't call the _alloca function explicitly.

(array size matters. if i change 10240 -> 128, everything ok)

I tried gcc option -fno-builtin-alloca or -fno-builtin, but no luck.

Is it possible to make gcc not to use _alloca ? (or adjust the threshold?)

like image 846
shkim Avatar asked Feb 27 '10 16:02

shkim


1 Answers

Best thing to do would be to compile all code with VC++. If that's not possible..

You should use the mingw gcc instead of the cygwin one. It's designed to output code that will be linked against the VC++ runtime, not the cygwin libraries. In particular, it will call the VC++ runtime function __chkstk instead of __alloca.

like image 175
andrewffff Avatar answered Nov 15 '22 08:11

andrewffff