Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MinGW g++: Multiple definition of vsnprintf when using to_string

I just started using MinGW for Windows. When trying to create executable using

g++ a.cpp -o a.exe -std=c++14

for the code below:

#include <string>

using namespace std;

int main()
{
    string x = to_string(123);
    return 0;
}

I'm getting following error:

C:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../libmingwex.a(vsnprintf.o):(.text+0x0): multiple definition of vsnprintf
C:\Users\..\Local\Temp\cc4sJDvK.o:c:/mingw/include/stdio.h:426: first defined here
collect2.exe: error: ld returned 1 exit status

What is the root cause for this error and how can I make it go away? While I can easily find a replacement for to_string() function I'm not sure what is causing this error to occur in the first place.

like image 574
Devotion Avatar asked Apr 08 '17 13:04

Devotion


3 Answers

This issue, i.e. multiple definition of vsnprintf, still exists in MinGW as December 2019.

After investigating a lot, I found the solution in the official mailing list.

It's a bug in mingwrt-5.2.2. Downgrading to the mingwrt-5.2.1 version solves that issue. To do that, just input the following command:

mingw-get upgrade mingwrt=5.2.1

Then restart the MinGW shell.

Read the full story here.

Note: MinGW-w64 and MinGW are separate projects, so the accepted solution is not so helpful to me, as I want to keep MinGW and not to move to MinGW-w64.

like image 160
SiZiOUS Avatar answered Nov 20 '22 10:11

SiZiOUS


Installing MinGW packages mingw32-libmingwex-* will link an appropriate version of vsnprintf and avoid the linker error.

like image 44
thoughtcrimes Avatar answered Nov 20 '22 10:11

thoughtcrimes


I solved this issue using MinGW w64 compiler

  1. download mingw-w64-install.exe
  2. setup to Version: 6.3.0, Architecture: i686, Threads: posix, Exception: dwarf and Build revision: 2.

I hope this will be of some help.

like image 7
keroberotte Avatar answered Nov 20 '22 09:11

keroberotte