如何使用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.

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

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

最佳答案

尝试

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

反而。我的原始编译尝试成功了,我感到有些惊讶,因为msvcr90msvcrt(默认情况下,MinGW会链接)之间的定义应该有冲突。这样,就链接了msvr90,而没有冲突的msvcrt,但是为了初始化运行时库而添加了libgcc

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

关于gcc - 如何使用mingw gcc链接到msvcr90.dll?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3402252/

10-13 05:49