开始使用 ISOCPP.net C++ build for windows 时遇到问题 (nuwen)
having trouble getting started with ISOCPP.net C++ build for windows (nuwen)
我从 isocpp.org 'Get started' 设置了一个最小的 MinGW (nuwen),它是为 windows
编译的 gcc 版本 6.1.0
这是我的代码
#include <stdio.h>
#include <string>
int main (int argc, char* argv[]) {
printf ("hello world\n");
std::string mystring {"my string"};
}
我不断收到以下错误(以及其他错误)
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
我做了什么
- 已检查包含目录中是否存在字符串文件
CPLUS_INCLUDE_PATH=C:\util\MinGW\include;C:\util\MinGW\include\freetype2
C_INCLUDE_PATH=C:\util\MinGW\include;C:\util\MinGW\include\freetype2
- 已检查 'string' 文件中是否存在分配器
我是否需要添加另一个包含文件才能使其正常工作?
您应该使用 g++
编译代码(参见 Compiling a C++ program with gcc)。
同时使用 --std=c++11
开关 (g++ --std=c++11
) 或更改
std::string mystring {"my string"};
进入
std::string mystring = "my string";
(uniform initialization is a C++11 feature and Nuwen MinGW Distro v 14.0 使用 C++03 作为默认模式)。
我从 isocpp.org 'Get started' 设置了一个最小的 MinGW (nuwen),它是为 windows
编译的 gcc 版本 6.1.0这是我的代码
#include <stdio.h>
#include <string>
int main (int argc, char* argv[]) {
printf ("hello world\n");
std::string mystring {"my string"};
}
我不断收到以下错误(以及其他错误)
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
我做了什么
- 已检查包含目录中是否存在字符串文件 CPLUS_INCLUDE_PATH=C:\util\MinGW\include;C:\util\MinGW\include\freetype2 C_INCLUDE_PATH=C:\util\MinGW\include;C:\util\MinGW\include\freetype2
- 已检查 'string' 文件中是否存在分配器
我是否需要添加另一个包含文件才能使其正常工作?
您应该使用 g++
编译代码(参见 Compiling a C++ program with gcc)。
同时使用 --std=c++11
开关 (g++ --std=c++11
) 或更改
std::string mystring {"my string"};
进入
std::string mystring = "my string";
(uniform initialization is a C++11 feature and Nuwen MinGW Distro v 14.0 使用 C++03 作为默认模式)。