shkim
shkim

Reputation: 1183

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?)

Upvotes: 5

Views: 3127

Answers (4)

Lazer
Lazer

Reputation: 94940

some related discussions:

Upvotes: 0

R Samuel Klatchko
R Samuel Klatchko

Reputation: 76581

It looks like _alloca has been deprecated by Microsoft and is no longer in their runtime libraries after VS2005. Newer runtime libraries support _malloca.

Your options don't look good. You can try to build with VS2005 instead. Perhaps cygwin has an option where you can tell it you are using a newer runtime library (and if they don't support that yet, you could file it as a feature request).

Upvotes: 1

andrewffff
andrewffff

Reputation: 579

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.

Upvotes: 7

Paul R
Paul R

Reputation: 213120

You could just write your own _alloca routine and link against that. Look at the gcc library source to see what it's supposed to do.

Upvotes: 3

Related Questions