使用代码块13.12,MinGW 4.8.1和SFML 2.1时,某些C ++ 11功能缺失

时间:2014-01-12 14:33:17

标签: c++11 mingw codeblocks sfml

在用尽所有努力后转向Stack Overflow 我在Windows 7 OS 64位系统上运行Code Blocks 13.12和MinGW 4.8.1。我花了两天时间试图让编译器(静态地)链接到SFML 2.1库。我遵循了SFML tutorialthis视频教程 - 在最终链接之前重新安装代码块和MinGW两次。
之后我很欣慰SFML被认可了,但是当我尝试构建和运行时,我得到了50个错误,建议C ++ 11的功能不是。
在编译器选项中添加了-std=gnu++11,其中13个错误消失了 剩下的错误都分为两类:互斥锁不是标准符号的成员,而从时间t开始不是计时:: _ V2 ::稳定时钟的成员。我甚至不确定_V2是什么。

我错过了什么?

-------------- Build: Release in PumpTracker2.0 (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -std=gnu++11 -DSFML_STATIC -O2 -std=gnu++11 -IC:\SFML-2.1\include -IC:\SFML-2.1\include -c C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp -o obj\Release\main.o

In file included from C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp:25:0:
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\Account.h:37:1: error: 'mutex' in namespace 'std' does not name a type
 std::mutex mu;
 ^
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\Account.h:86:22: error: 'to_time_t' is not a member of 'std::chrono::_V2::steady_clock'
   time_t currentTp = std::chrono::steady_clock::to_time_t(newly);

C:\Users\WITcom\Desktop\C++\PumpTracker2.0\Account.h:94:48: error: 'from_time_t' is not a member of 'std::chrono::_V2::steady_clock'
   std::chrono::steady_clock::time_point tNew = std::chrono::steady_clock::from_time_t(currentTp);
                                                ^
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp:51:2: error: 'mutex' is not a member of 'std'
  std::mutex mu3;
  ^
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp:51:13: error: expected ';' before 'mu3'
  std::mutex mu3;
             ^
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp:52:19: error: 'mutex' was not declared in this scope
  std::unique_lock<mutex> locker3(mu3, std::defer_lock);
                   ^
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp:52:24: error: template argument 1 is invalid
  std::unique_lock<mutex> locker3(mu3, std::defer_lock);
                        ^
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp:52:33: error: invalid type in declaration before '(' token
  std::unique_lock<mutex> locker3(mu3, std::defer_lock);

C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp:214:22: error: 'to_time_t' is not a member of 'std::chrono::_V2::steady_clock'
       pS->tpNewest = std::chrono::steady_clock::to_time_t(NextPump);
                      ^
C:\Users\WITcom\Desktop\C++\PumpTracker2.0\main.cpp:245:51: error: 'from_time_t' is not a member of 'std::chrono::_V2::steady_clock'
       std::chrono::steady_clock::time_point TT2 = std::chrono::steady_clock::from_time_t(pS->tpNewest);
                                                   ^
Process terminated with status 1 (0 minute(s), 4 second(s))
37 error(s), 47 warning(s) (0 minute(s), 4 second(s))

1 个答案:

答案 0 :(得分:0)

如前所述,如果您想使用最新功能,最初的MinGW发行版不是最好的发行版。相反,有Nuwen(Stephan T. Lavavej的网站)以及提供MinGW Builds二进制文件的MinGW-w64等项目。

提及SFML具有误导性,因为这些问题根本与SFML无关。但请记住,如果更改编译器,则必须重建SFML!

下一步,发布重现错误的源代码的最小示例非常重要,因为现在,我们只能根据错误猜出出错了。

如果你没有明确使用GNU扩展,你应该使用-std=c++11而不是-std=gnu++11,如果你看一下build命令,你会注意到它被包含两次,这不是必要的。

现在有人猜测错误:

  • Account.h - 确保包含<mutex>标题。
  • main.cpp - 确保包含<mutex>标题。
  • main.cpp - 如果std::unique_lock<mutex>来自您的代码,那么您需要添加std::,即std::unique_lock<std::mutex>
  • main.cpp - time_t似乎已经解决了问题,但请务必确保包含<chrono><ctime&gt; (因为time_t中定义了<ctime>