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
Do I need to add another include file to make it work?
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With