Search code examples
c++gccmingw-w64msys2

Can't find entry point (_ZSt28__throw_bad_array_new_lengthv) in DLL (filepath)


The error

The exact error is the title of the question. A picture of the error.

It happens when I use vectorName.push_back() function. I recreated it with just this simple code:

#include <iostream>
#include <vector>

using namespace std;

int main() {
    vector <int> vec = {};
    vec.push_back(2);
    return 0;
}

Compiler and setup information

I'm using msys2, and I set it up using this guide

I have no idea if this is relevant or not, but I used tdm-gcc before this.

Research

A fix is almost nowhere to be found, or I just didn't look hard enough. I have found some posts about the _ZSt28__throw_bad_array_new_lengthv, but not with entry point. And because I didn't find anything about this exact issue, I didn't try anything.


Solution

  • Problem: "the procedure entry point _zst28__throw_bad could not be located in the dynamic link library"

    (with msys2 mingw64)

    Solution: Modify the system environment variables (requires admin rights)

    Start the windows commandline (cmd.exe) as admin (right-click run as administrator). Then enter this command:

    "C:\Windows\system32\rundll32.exe" sysdm.cpl,EditEnvironmentVariables
    

    Then edit the PATH at the bottom (under Systemvariables), and make sure that C:\msys64\mingw64\bin is right at the top position.

    Done.

    Check as follows in cmd:

    echo %PATH%
    

    You can also non-persistenly edit the PATH from a cmd as follows (also does not require admin rights):

    set PATH=C:\msys64\mingw64\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem