如何使用 mingw gcc 链接 msvcr90.dll?

发布于 2024-09-12 22:30:36 字数 1051 浏览 4 评论 0原文

如何使用 mingw gcc 链接 msvcr90.dll?我尝试了 -lmsvcr90,这是最小的示例:

#include <stdio.h>
int main(int argc, const char *argv[]) {
    printf("%s\n", "hello");
    return 0;
}

我的操作系统是 win7,使用 mingw gcc 4.5.0

$ gcc -v
...
gcc version 4.5.0 (GCC)
$ gcc hello.c -lmsvcr90
$ a

然后我收到此错误:

R6034

    An application has made an attempt to load the C runtime library incorrectly.
    Please contact the application's support team for more information.

我缺少哪一部分?

edit1:

@user440813 看来我的mingw和你的很不一样。

$ gcc h.c -nostdlib -lmsvcr70 -lgcc -o h.exe
d:/mingw/bin/../lib/gcc/mingw32/4.5.0/libgcc.a(__main.o):(.text+0x5a): undefined reference to `atexit'
d:/mingw/bin/../lib/gcc/mingw32/4.5.0/libgcc.a(__main.o):(.text+0xc2): undefined reference to `atexit'
collect2: ld returned 1 exit status

然后我嘲笑了 int atexit ( void ( * function ) (void) ) {return 0;} 并再次得到了 R6034 ...

How to link against msvcr90.dll with mingw gcc? I tried -lmsvcr90, here's the minimal example:

#include <stdio.h>
int main(int argc, const char *argv[]) {
    printf("%s\n", "hello");
    return 0;
}

My OS is win7, with mingw gcc 4.5.0

$ gcc -v
...
gcc version 4.5.0 (GCC)
$ gcc hello.c -lmsvcr90
$ a

Then I got this error:

R6034

    An application has made an attempt to load the C runtime library incorrectly.
    Please contact the application's support team for more information.

Which part am I missing ?

edit1:

@user440813 Seems my mingw is very different from yours.

$ gcc h.c -nostdlib -lmsvcr70 -lgcc -o h.exe
d:/mingw/bin/../lib/gcc/mingw32/4.5.0/libgcc.a(__main.o):(.text+0x5a): undefined reference to `atexit'
d:/mingw/bin/../lib/gcc/mingw32/4.5.0/libgcc.a(__main.o):(.text+0xc2): undefined reference to `atexit'
collect2: ld returned 1 exit status

Then I mocked int atexit ( void ( * function ) (void) ) {return 0;} and got R6034 again ...

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

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

发布评论

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

评论(1

与他有关 2024-09-19 22:30:36

尝试

gcc hello.c -nostdlib -lmsvcr90 -lgcc -o hello.exe

一下。我对您最初的编译尝试成功感到有点惊讶,因为 msvcr90msvcrt (MinGW 默认链接的)之间应该存在冲突的定义。这样,msvr90 就会被链接,冲突的 msvcrt 则不会,但会添加 libgcc 以初始化运行时库。

我的计算机上没有 msvcr90.dll,但我能够验证类似的调用是否适用于 msvcr100.dll

Try

gcc hello.c -nostdlib -lmsvcr90 -lgcc -o hello.exe

instead. I'm a little surprised that your original compilation attempt succeeded, since there should've been conflicting definitions between msvcr90 and msvcrt (which MinGW links in by default). This way, msvr90 gets linked in, the conflicting msvcrt doesn't, but libgcc gets added in order to initialize the runtime library.

I don't have msvcr90.dll on my computer, but I was able to verify that the analogous invocation works with msvcr100.dll.

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