3

I have a minimal MinGW (nuwen) set up from isocpp.org 'Get started' which is gcc version 6.1.0 compiled for windows

this is my code

#include <stdio.h>
#include <string>

int main (int argc, char* argv[]) {
    printf ("hello world\n");

    std::string mystring {"my string"};

}

I keep getting the following error (among others)

C:\util\MinGW\proj>gcc main.cpp

C:\Users\gmyer\AppData\Local\Temp\ccXSjGdh.o:main.cpp:(.text+0x2e): undefined reference to `std::allocator::allocator()' collect2.exe: error: ld returned 1 exit status

What I have done

  • checked that string file exists in include directory CPLUS_INCLUDE_PATH=C:\util\MinGW\include;C:\util\MinGW\include\freetype2 C_INCLUDE_PATH=C:\util\MinGW\include;C:\util\MinGW\include\freetype2
  • checked that allocator exists in the 'string' file

Do I need to add another include file to make it work?

manlio
  • 18,345
  • 14
  • 76
  • 126
Gregg
  • 2,444
  • 1
  • 12
  • 21

1 Answers1

1

You should compile the code with g++ (see Compiling a C++ program with gcc).

Also use the --std=c++11 switch (g++ --std=c++11) or change

std::string mystring {"my string"};

into

std::string mystring = "my string";

(uniform initialization is a C++11 feature and Nuwen MinGW Distro v 14.0 uses C++03 as default mode).

Community
  • 1
  • 1
manlio
  • 18,345
  • 14
  • 76
  • 126