使用代码块13.12,MinGW 4.8.1和SFML 2.1时,缺少一些C ++ 11功能 [英] Some C++11 features missing when using Code Blocks 13.12, MinGW 4.8.1 and SFML 2.1

查看:221
本文介绍了使用代码块13.12,MinGW 4.8.1和SFML 2.1时,缺少一些C ++ 11功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

耗尽我的努力后,转到堆栈溢出。

我在Windows 7操作系统64位系统上运行代码块13.12和MinGW 4.8.1。我花了两天时间试图让编译器链接(静态)到SFML 2.1库。我同时遵循SFML 教程视频教程 - 重新安装代码块和MinGW两次,最后链接之前。

之后我很高兴SFML被认可,但我有50错误,当我试图构建和运行建议C ++ 11功能不是。

添加 -std = gnu + +11 到编译器选项,其中13个错误消失了。

剩余的错误分为两类: mutex不是std的成员从时间t不是chrono :: _ V2 :: stable clock 的成员。我甚至不知道_V2是什么。

Turning to Stack Overflow after exhausting all my efforts.
I'm running Code Blocks 13.12 and MinGW 4.8.1 on a Windows 7 OS 64bit system. I spent two days trying to get the compiler to link (statically) to the SFML 2.1 library. I followed both the SFML tutorial and this video tutorial- reinstalling both Code Blocks and MinGW twice before it finally linked.
After that I was relieved that SFML was recognized, but I got 50 errors when I tried to build and run that suggested C++11 features weren't.
Added -std=gnu++11 to compiler options and 13 of those errors went away.
The remaining errors all fall into two categories: mutex is not a member of std and from time t is not a member of chrono::_V2::steady clock. I'm not even sure what _V2 is.

我失踪了什么?

-------------- 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))


推荐答案

最好的一个去,如果你想去与最新的功能。相反,有像 Nuwen (Stephan T. Lavavej的网站)以及 MinGW Builds ,提供 MinGW-w64 二进制文件。

As already mentioned the original MinGW distribution is not the best one to go with, if you want to go with up-to-date features. Instead there are projects like Nuwen (Stephan T. Lavavej's website) as well as MinGW Builds that provide MinGW-w64 binaries.

提到SFML是误导,因为问题与SFML无关。但是请记住,如果您更改了编译器,则必须重建SFML!

The mentioning of SFML is misleading, since the problems have nothing to do with SFML at all. Keep in mind however that you'll have to rebuild SFML if you change the compiler!

作为下一步,重要的是发布一个最小的例子重现错误的源代码,因为现在,我们只能根据错误猜测出现了什么问题。

As a next step, it would've been important to post a minimal example of the source code that reproduces the errors, because right now, we can only guess what's going wrong, based on the errors.

如果你不明确使用GNU扩展,你应该使用 -std = c ++ 11 而不是 -std = gnu ++ 11

If you don't use the GNU extensions explicitly, you should use -std=c++11 instead of -std=gnu++11 and if you look at the build command, you'll notice that it's included twice, which is not necessary.

现在有一些关于错误的猜测:

And now to some guessing about the errors:


  • Account.h - 确保< mutex> c> c> c> c> std :: unique_lock< mutex>< c $ c>头包括在内。

  • 来自您的代码,那么您需要添加 std :: ,即 std :: unique_lock< std :: mutex> ;
  • main.cpp - time_t 事情似乎得到解决,但确保无论如何包括< chrono> < ctime > time_t < ctime> 中定义。

  • Account.h - Make sure the <mutex> header is included.
  • main.cpp - Make sure the <mutex> header is included.
  • main.cpp - If std::unique_lock<mutex> is from your code, then you need to add std::, i.e. std::unique_lock<std::mutex>.
  • main.cpp - time_t things seem to be resolved, but make sure anyways to include <chrono> and <ctime> (since time_t is defined in <ctime>).

这篇关于使用代码块13.12,MinGW 4.8.1和SFML 2.1时,缺少一些C ++ 11功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆