views:

388

answers:

4

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

+1  A: 

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.

Paul R
When I implemented _alloca in VS2008, I got: error C2169: '_alloca' : intrinsic function, cannot be defined
shkim
I think you'd probably want to implement your custom _alloca using gcc rather then Visual Studio.
Paul R
+5  A: 

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.

Andrew
I tried MinGW (gcc 3.4.5 mingw-vista special r3) and compiled a simple C source. but the dumpbin result showed __alloca dependency:dumpbin /symbols test.obj...00C 00000000 UNDEF notype External | __alloca...is there a special option for mingw?
shkim
Ah, sorry. The mingw.org gcc does this. The TDM GCC 4.x mingw build outputs __chkstk. http://www.tdragon.net/recentgcc/
Andrew
Thank you. I checked TDM gcc always outputs __chkstk, but VC2008 outputs _chkstk on Release build, and _alloca_probe on Debug build. I think I should edit the code to use local varaibles under 4K.
shkim
A: 

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

R Samuel Klatchko
A: 

some related discussions:

Lazer