2

This is my first experience with g++, so I might be missing something obvious. I installed MinGW (6.3.0) and am compiling following snippet on Windows. Compiling with no flags (that is required by the task) so just "g++ my_main.cpp"

int main(int argc, char** argv) 
{
    int s = 10;
    int *a = new int[s];
    delete[] a;
    return 0;
}

It compiles, but upon running displays error window with close translation "Unable to find entry point in __cxa_throw_bad_array_new_length not found in DLL libstdc++-6.dll". When I replace new int[s] with new int[10] it compiles and runs with no problems. What is the catch?

EDIT: mingw.org seems to be an outdated project, installed MinGW-w64, all works as a charm.

  • 1
    ISO C++ doesn't not allow to specify array size from a variable. Use a vector instead. – Chelmy88 Sep 24 '19 at 22:58
  • 7
    @Chelmy88 I don't believe that this code is using variable-length arrays, which are indeed not standard C++. This seems like a more straightforward case of using the `new[]` operator. – templatetypedef Sep 24 '19 at 23:00
  • Potentially related? https://stackoverflow.com/questions/13360014/the-procedure-entry-point-znst8-detail15-list-node-base7-m-hookeps0-could-not – templatetypedef Sep 24 '19 at 23:02
  • @Chelmy88 You need to distinguish global arrays and those with local storage duration from dynamically allocated ones. The former indeed do require compile time constant size (otherwise it would be the famous VLA), the latter *not*. The code in the question is totally legal. – Aconcagua Sep 24 '19 at 23:06
  • Hi all, indeed you are correct I read the code a bit too fast. Sorry – Chelmy88 Sep 24 '19 at 23:07
  • 1
    Side note: Linux g++ accepts without any issue. – Aconcagua Sep 24 '19 at 23:10
  • Looks like you mixed runtime/dll platform architectures, you are building 32 or 64 bit and mixing with improper 64 or 32 bit dll. – 273K Sep 24 '19 at 23:12
  • @Chelmy88 I cannot use a vector, I cannot specify any flags by the conditions of the task, so I cant link standard library – Problem Sir Sep 24 '19 at 23:14
  • @S.M. I have a 64 bit system, and the MinGW specifically mention on their site that it only has 32 version, which however works on any 64 bit system. If you imply that I linked something myself that is not the case, I just use it out of the box. – Problem Sir Sep 24 '19 at 23:24
  • What mingw distribution did you use? These days there seem to be dozens of them. – user4581301 Sep 24 '19 at 23:42
  • This seems related: [program linking fails when using custom built gcc](https://stackoverflow.com/questions/29230777/program-linking-fails-when-using-custom-built-gcc) – Max Vollmer Sep 25 '19 at 02:52
  • 1
    You might try: https://en.wikipedia.org/wiki/MinGW#MinGW-w64 (link to project there). – Aconcagua Sep 25 '19 at 05:18
  • @user4581301 Downloaded from http://www.mingw.org/, this is official, isn't it? – Problem Sir Sep 25 '19 at 09:03
  • 1
    @ProblemSir mingw.org is old , mingw-w64 is a fork that is under active development – M.M Sep 25 '19 at 12:26
  • @M.M and Aconcagua thanks! mingw-w64 compiles and runs with no problem :) – Problem Sir Sep 25 '19 at 12:39
  • 2
    @ProblemSir OK; as discussed on the question I linked you may well have old mingw version DLLs on your system path, I would recommend tracking them down and removing them to avoid any similar problems in future – M.M Sep 25 '19 at 12:40

0 Answers0