Mingw-packages: multiple definition of 'vsnprintf' with latest mingw-w64 update

Created on 14 Mar 2020  路  14Comments  路  Source: msys2/MINGW-packages

With the latest mingw-w64 update (mingw-w64-x86_64-gcc-9.3.0-1, mingw-w64-x86_64-crt-git-8.0.0.5681.09a1e9b4-1) I'm getting the following linker error when compiling Inkscape:

cmd.exe /C "cd . && C:\msys64\mingw64\bin\g++.exe  -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Werror=format -Werror=format-security -mms-bitfields -mwindows -mthreads -m64 -pthread -mms-bitfields -fopenmp -O3 -DNDEBUG   -shared -o bin\libinkscape_base.dll -Wl,--out-implib,lib\libinkscape_base.dll.a -Wl,--major-image-version,0,--minor-image-version,0 @CMakeFiles\inkscape_base.rsp  && cd ."
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.3.0/../../../../x86_64-w64-mingw32/lib/../lib/libmsvcrt.a(lib64_libmsvcrt_os_a-vsnprintf.o): in function `__ms_vsnprintf':
D:/mingwbuild/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/vsnprintf.c:21: multiple definition of `vsnprintf'; lib/libnrtype_LIB.a(FontInstance.cpp.obj):FontInstance.cpp:(.text$vsnprintf[vsnprintf]+0x0): first defined here
collect2.exe: error: ld returned 1 exit status

It seems related to something mentioned in this mingw-w64 thread:
https://sourceforge.net/p/mingw-w64/mailman/mingw-w64-public/thread/de9f222f-57a6-e2cb-7ebe-f61a9a8051f2%40126.com/#msg36930964

@lhmouse Can you shed some light on this? Is this an issue in mingw-w64 or something I can fix on my end? If it's an issue in mingw-w64 is there a workaround?

Most helpful comment

Did you install the latest mingw-w64-headers before building mingw-w64-crt?

Ah, stupid me. I had downgraded them before to work around the issue and forgot to upgrade it again before attempting the build with the fix.

I can confirm https://sourceforge.net/p/mingw-w64/mingw-w64/ci/629fd2b1abe6d6c12b08e477a7ce32c8fef8c667/ builds properly and fixes the issue reported initially.

Maybe we can have a package update for mingw-w64-crt-git @Alexpux ?

All 14 comments

Cc @mstorsjo who recently touched vsnprintf bits

Looks like that the inline function vsnprintf() was referenced _FontInstance.cpp_ but failed to be inlined and resulted in a definition with external linkage. Prior to that commit, vsnprintf() was provided as an alias in _MSVCR*.DLL_, in which case it was ignored and the former was picked by the linker. But now vsnprintf() is provided by libmingwex instead, and if some code references it indirectly, the linker will be confused as it can now see both.

Reduced testcase

#include <stdio.h>
#include <stdarg.h>

char* fstr(const char* fmt, ...)
  {
    static char str[100];
    va_list ap;
    va_start(ap, fmt);
    vsnprintf(str, sizeof(str), fmt, ap);
    va_end(ap);
    return str;
  }

int main(void)
  {
    fstr("value = %u", 12345);
  }

outputs

E:\Desktop>gcc -xc -O0 test.cc

E:\Desktop>g++ -O0 test.cc
C:/MinGW/MSYS2/mingw64/lib/gcc/x86_64-w64-mingw32/9.2.1/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/MinGW/MSYS2/mingw64/lib/gcc/x8
6_64-w64-mingw32/9.2.1/../../../../x86_64-w64-mingw32/lib/../lib/libmsvcrt.a(lib64_libmsvcrt_os_a-vsnprintf.o): in function `__ms_vs
nprintf':
E:/GitHub/MINGW-packages/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/vsnprintf.c:21: multiple definition of `vsnprintf'; C:\
Users\lh_mouse\AppData\Local\Temp\ccUHY0bd.o:test.cc:(.text$vsnprintf[vsnprintf]+0x0): first defined here
collect2.exe: error: ld returned 1 exit status

When compiled as C, those functions are specified as static __inline__ so the inline definitions are not visible outside. I think we can make them static inline in C++ too.

BTW: The behavior of vsnprintf() is subject to __USE_MINGW_ANSI_STDIO so __attribute__((__gnu_inline__)) is not an option.

All the non-static inline forms in headers are really tricky... Another solution is to split stdio/vsnprintf.c into one main, providing __ms_vsnprintf, and a second file that provides vsnprintf - either as a copy of the former, or just calling __ms_vsnprintf. Then the second one will only ever be included if it's needed, and shouldn't be able to cause conflicts like this.

I posted one possible fix for this to the mingw-w64-public mailing list.

Link to mailing list thread mentioned by Martin:
https://sourceforge.net/p/mingw-w64/mailman/message/36948917/

Thanks for looking into this @mstorsjo and @lhmouse !

The fix is pushed now, at https://sourceforge.net/p/mingw-w64/mingw-w64/ci/b46a25b433f5adf23418994df484b2e6b3f9e566/ (but if looking for a commit to build, the following one, 629fd2b1abe6d6c12b08e477a7ce32c8fef8c667, updated Makefile.in and is the one you want to check out).

Dear all,

I got this error today when I try to compile one of my project.
So to not wait for the new release, I try to download the previous version of my package 8.0.0.5681 (http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-crt-git-8.0.0.5647.1fe2e62e-1-any.pkg.tar.xz) and badly replace file libmsvcrt.a

It does not work (too simple). Do you know if there is a way to use the previous version of mingw-w64-x86_64-crt-git with a safe pacman command?

Regards.

@mstorsjo I just tried to build https://sourceforge.net/p/mingw-w64/mingw-w64/ci/629fd2b1abe6d6c12b08e477a7ce32c8fef8c667/ to verify the fix.

Unfortunately the build fails (full build log):

E:/Temp/MSYS2/MINGW-packages/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/ucrt__vscprintf.c:11:5: error: redefinition of '_vscprintf'
   11 | int _vscprintf(const char * __restrict__ _Format, va_list _ArgList)
      |     ^~~~~~~~~~
In file included from E:/Temp/MSYS2/MINGW-packages/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/ucrt__vscprintf.c:9:
C:/msys64/mingw64/x86_64-w64-mingw32/include/stdio.h:946:15: note: previous definition of '_vscprintf' was here
  946 |   int __cdecl _vscprintf(const char * __restrict__ _Format,va_list _ArgList)
      |               ^~~~~~~~~~

Any ideas?

There are also some warnings btw:

E:/Temp/MSYS2/MINGW-packages/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/snprintf_alias.c:16:13: warning: no previous prototype for 'snprintf' [-Wmissing-prototypes]
   16 | int __cdecl snprintf(char *buffer, size_t n, const char *format, ...)
      |             ^~~~~~~~
E:/Temp/MSYS2/MINGW-packages/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/vsnprintf_alias.c:16:13: warning: no previous prototype for 'vsnprintf' [-Wmissing-prototypes]
   16 | int __cdecl vsnprintf(char *buffer, size_t n, const char *format, va_list arg)
      |             ^~~~~~~~~

@mstorsjo I just tried to build https://sourceforge.net/p/mingw-w64/mingw-w64/ci/629fd2b1abe6d6c12b08e477a7ce32c8fef8c667/ to verify the fix.

Unfortunately the build fails (full build log):

E:/Temp/MSYS2/MINGW-packages/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/ucrt__vscprintf.c:11:5: error: redefinition of '_vscprintf'
   11 | int _vscprintf(const char * __restrict__ _Format, va_list _ArgList)
      |     ^~~~~~~~~~
In file included from E:/Temp/MSYS2/MINGW-packages/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/ucrt__vscprintf.c:9:
C:/msys64/mingw64/x86_64-w64-mingw32/include/stdio.h:946:15: note: previous definition of '_vscprintf' was here
  946 |   int __cdecl _vscprintf(const char * __restrict__ _Format,va_list _ArgList)
      |               ^~~~~~~~~~

Any ideas?

There are also some warnings btw:

E:/Temp/MSYS2/MINGW-packages/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/snprintf_alias.c:16:13: warning: no previous prototype for 'snprintf' [-Wmissing-prototypes]
   16 | int __cdecl snprintf(char *buffer, size_t n, const char *format, ...)
      |             ^~~~~~~~
E:/Temp/MSYS2/MINGW-packages/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/stdio/vsnprintf_alias.c:16:13: warning: no previous prototype for 'vsnprintf' [-Wmissing-prototypes]
   16 | int __cdecl vsnprintf(char *buffer, size_t n, const char *format, va_list arg)
      |             ^~~~~~~~~

Did you install the latest mingw-w64-headers before building mingw-w64-crt? The change in https://sourceforge.net/p/mingw-w64/mingw-w64/ci/d8275c196dfd26d137ae59373c1506c22b450f32 contained a change to both, and they need to be in sync.

Finding the exact same issue here, it would be of great help if a fix or workaround would be issued ASAP to be able to build and work again.

Did you install the latest mingw-w64-headers before building mingw-w64-crt?

Ah, stupid me. I had downgraded them before to work around the issue and forgot to upgrade it again before attempting the build with the fix.

I can confirm https://sourceforge.net/p/mingw-w64/mingw-w64/ci/629fd2b1abe6d6c12b08e477a7ce32c8fef8c667/ builds properly and fixes the issue reported initially.

Maybe we can have a package update for mingw-w64-crt-git @Alexpux ?

Fixed in 701f6a36ecd20a1b2314bab5ce0c07692822a6e6.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kryptan picture kryptan  路  5Comments

Ede123 picture Ede123  路  7Comments

dimztimz picture dimztimz  路  9Comments

oscarbg picture oscarbg  路  7Comments

WilliamKappler picture WilliamKappler  路  4Comments