c++ - 开始使用适用于 Windows 的 ISOCPP.net C++ 构建时遇到问题 (nuwen)

标签 c++ compiler-errors mingw

我从 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
  • 检查分配器是否存在于“字符串”文件中

我是否需要添加另一个包含文件才能使其工作?

最佳答案

您应该使用 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 是 C++11 的特性,Nuwen MinGW Distro v 14.0 使用 C++03 作为默认模式)。

关于c++ - 开始使用适用于 Windows 的 ISOCPP.net C++ 构建时遇到问题 (nuwen),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37679989/

相关文章:

c++ - 在哪里可以找到 MinGW C 库中所有函数的列表?

c++ - OpenMPI MPI_Gather 段错误或断言错误

java - 无法编译内部类源文件,导致错误?

c++ - 如何在 C++ 中确定一个 win32 线程处于 Wait 或 Join 或 Sleep 状态

java - 类文件使用导入但报告 Unresolved 编译问题

c - 错误 :expected expression before 'int' when casting float or double into integer in C

c - pthread_create空间不足

java - 简单的 java jni 教程失败

c++ - 如果函数抛出的异常可能未被捕获,如何销毁局部变量?

c++ - 嵌套循环到尾递归