如何在没有 _alloca 的情况下进行 GCC 编译?

发布于 2024-08-23 17:03:03 字数 461 浏览 4 评论 0原文

由于某种原因,我应该使用 gcc 编译 C 文件,然后链接到 Visual C++ 2008 项目。

(我使用的是当前最新的gcc版本:cygwin gcc 4.3.4 20090804。)

但是有一个问题:gcc总是用_alloca分配一个大数组,

而VC链接器无法解析符号__alloca。

例如,

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

尽管我没有显式调用 _alloca 函数,但此代码会产生 _alloca 依赖项。

(数组大小很重要。如果我更改 10240 -> 128,一切正常)

我尝试了 gcc 选项 -fno-builtin-alloca 或 -fno-builtin,但没有运气。

是否可以使 gcc 不使用 _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?)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

无所谓啦 2024-08-30 17:03:03

最好的办法是用 VC++ 编译所有代码。如果这是不可能的..

您应该使用 mingw gcc 而不是 cygwin gcc。它旨在输出将链接到 VC++ 运行时的代码,而不是 cygwin 库。特别是,它将调用 VC++ 运行时函数 __chkstk 而不是 __alloca。

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.

你的他你的她 2024-08-30 17:03:03

您可以编写自己的 _alloca 例程并链接到它。查看 gcc 库源代码以了解它应该做什么。

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.

清旖 2024-08-30 17:03:03

看起来 _alloca 已被弃用Microsoft 在 VS2005 之后不再在其运行时库中。较新的运行时库支持 _malloca

你的选择看起来不太好。您可以尝试使用 VS2005 进行构建。也许 cygwin 有一个选项,您可以告诉它您正在使用较新的运行时库(如果他们还不支持,您可以将其归档为功能请求)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文