Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#282 _MSC_VER and __CRT_INLINE

closed-invalid
nobody
crt (84)
5
2012-04-03
2012-04-03
Jack Applegame
No

Compiler inserts visible standard library functions into object files when _MSC_VER macro is defined:

gcc -O2 -D_MSC_VER -c x.c
gcc -O2 -D_MSC_VER -c y.c
gcc -o a.exe x.o y.o
y.o:y.c:(.text+0x0): multiple definition of `_strncasecmp'
x.o:x.c:(.text+0x0): first defined here
y.o:y.c:(.text+0x10): multiple definition of `_strcasecmp'
x.o:x.c:(.text+0x10): first defined here
ld.exe: x.o: bad reloc address 0x7 in section `.text.startup'
collect2.exe: error: ld returned 1 exit status

Discussion

  • Jack Applegame
    Jack Applegame
    2012-04-03

    // x.c
    #include <string.h>
    int fy(void);
    int main() {
    fy();
    strcmp("Hello", "World");
    return 0;
    }

    // y.c
    #include <string.h>
    int fy(void) {
    return strcmp("Hello", "World");
    }

     
  • Jack Applegame
    Jack Applegame
    2012-04-03

    x.c and y.c

     
    Attachments
  • Ozkan Sezer
    Ozkan Sezer
    2012-04-03

    _MSC_VER is defined by MS Visual C compiler to identify itself. You aren't supposed to define _MSC_VER by yourself, and most definitely not when using gcc.

     
  • Ozkan Sezer
    Ozkan Sezer
    2012-04-03

    • status: open --> closed-invalid
     
  • Jack Applegame
    Jack Applegame
    2012-04-03

    But why mingw checks this macro? Some libraries uses _MSC_VER for internal purproses. For examle zziplib.
    mingw.org build compiles with _MSC_VER without any problem.

     
  • Jack Applegame
    Jack Applegame
    2012-04-03

    • status: closed-invalid --> open-invalid
     
  • Ozkan Sezer
    Ozkan Sezer
    2012-04-03

    • status: open-invalid --> closed-invalid
     
  • Ozkan Sezer
    Ozkan Sezer
    2012-04-03

    We check that macro because we have some experimental support for compiling our CRT using MSVC. Mingw.org doesn't check that macro because they don't support MSVC at all.

     
  • Jonathan Yong
    Jonathan Yong
    2012-04-03

    Regardless of whether other applications define it, _MSC_VER is for Visual Studio, you'd expect something that defines it to act like it. Unfortunately, this does not include GCC or mingw in general.