How to link against msvcr90.dll with mingw gcc?

此生再无相见时 提交于 2019-12-05 01:30:16

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/3402252/how-to-link-against-msvcr90-dll-with-mingw-gcc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!