• <small id='RdLU7'></small><noframes id='RdLU7'>

      <bdo id='RdLU7'></bdo><ul id='RdLU7'></ul>

    <tfoot id='RdLU7'></tfoot>

    <legend id='RdLU7'><style id='RdLU7'><dir id='RdLU7'><q id='RdLU7'></q></dir></style></legend>

      <i id='RdLU7'><tr id='RdLU7'><dt id='RdLU7'><q id='RdLU7'><span id='RdLU7'><b id='RdLU7'><form id='RdLU7'><ins id='RdLU7'></ins><ul id='RdLU7'></ul><sub id='RdLU7'></sub></form><legend id='RdLU7'></legend><bdo id='RdLU7'><pre id='RdLU7'><center id='RdLU7'></center></pre></bdo></b><th id='RdLU7'></th></span></q></dt></tr></i><div id='RdLU7'><tfoot id='RdLU7'></tfoot><dl id='RdLU7'><fieldset id='RdLU7'></fieldset></dl></div>

        std::this_thread::sleep_for() 和 GCC

        std::this_thread::sleep_for() and GCC(std::this_thread::sleep_for() 和 GCC)

          <bdo id='5eqCE'></bdo><ul id='5eqCE'></ul>
          1. <small id='5eqCE'></small><noframes id='5eqCE'>

              • <legend id='5eqCE'><style id='5eqCE'><dir id='5eqCE'><q id='5eqCE'></q></dir></style></legend>
                    <tbody id='5eqCE'></tbody>
                  <i id='5eqCE'><tr id='5eqCE'><dt id='5eqCE'><q id='5eqCE'><span id='5eqCE'><b id='5eqCE'><form id='5eqCE'><ins id='5eqCE'></ins><ul id='5eqCE'></ul><sub id='5eqCE'></sub></form><legend id='5eqCE'></legend><bdo id='5eqCE'><pre id='5eqCE'><center id='5eqCE'></center></pre></bdo></b><th id='5eqCE'></th></span></q></dt></tr></i><div id='5eqCE'><tfoot id='5eqCE'></tfoot><dl id='5eqCE'><fieldset id='5eqCE'></fieldset></dl></div>
                • <tfoot id='5eqCE'></tfoot>

                  本文介绍了std::this_thread::sleep_for() 和 GCC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当我尝试编译这个简单的程序时:

                  When I try to compile this simple program:

                  #include<thread>
                  
                  void f() {
                    std::this_thread::sleep_for(std::chrono::seconds(3));
                  }
                  
                  int main() {
                    std::thread t(f);
                    t.join();
                  }
                  

                  在 Ubuntu 10.04(32 位)上使用 gcc 4.4.3 版:

                  with gcc version 4.4.3 on Ubuntu 10.04 (32 bit):

                  $ g++ -std=c++0x -pthread a.cpp -o a
                  

                  我明白了:

                  error: ‘sleep_for’ is not a member of ‘std::this_thread’
                  

                  我查看了标题线程".
                  sleep_for() 受 _GLIBCXX_USE_NANOSLEEP 保护

                  I looked in header 'thread'.
                  sleep_for() is protected with _GLIBCXX_USE_NANOSLEEP

                  #ifdef _GLIBCXX_USE_NANOSLEEP
                  ...
                  /// sleep_for
                  template<typename _Rep, typename _Period>
                    inline void
                    sleep_for(const chrono::duration<_Rep, _Period>& __rtime)
                  ...
                  

                  为什么没有定义 _GLIBCXX_USE_NANOSLEEP?
                  我如何编译这个例子?

                  Why is _GLIBCXX_USE_NANOSLEEP not defined?
                  How do I get this example to compile?

                  2012 年 9 月 17 日更新(jogojapan):我今天在使用 GCC 4.7.1 时遇到了同样的问题.我想知道除了定义 _GLIBCXX_USE_NANOSLEEP 之外,是否有任何关于如何避免它的消息.我尝试使用 -std=gnu11,但无济于事.

                  Update 17 Sep 2012 (jogojapan): I ran into this same problem today, using GCC 4.7.1. I wonder if there is any news on how to avoid it, other than by defining _GLIBCXX_USE_NANOSLEEP. I tried using -std=gnu11, but to no avail.

                  GCC 4.4 还有一个旧的未解决的错误报告:https://bugs.launchpad.net/ubuntu/+source/gcc-4.4/+bug/608145

                  There is also an old, unresolved bug report for GCC 4.4: https://bugs.launchpad.net/ubuntu/+source/gcc-4.4/+bug/608145

                  2012 年 10 月 19 日更新(jogojapan):Jonathan Wakely 现在已经解释并解决了这个问题,作为对这个问题的回答:什么是_GLIBCXX_USE_NANOSLEEP?这对于那些自己构建 GCC 而不是使用现成包的人来说尤其重要.

                  Update 19 Oct 2012 (jogojapan): The issue has now been explained and resolved by Jonathan Wakely as an anwer to this question: What is _GLIBCXX_USE_NANOSLEEP all about? This is particularly relevant for anyone who builds GCC himself instead of using a ready-made package.

                  推荐答案

                  确认它在这里也不起作用.(最近的 GCC 4.6 快照).

                  Confirmed that it doesn't work here as well. (Recent GCC 4.6 snapshot).

                  在包含任何 std:: 标头之前,您可以做显而易见的事情并简单地定义它.有点脏,但会一直工作到 GCC 修复它(除非这是预期的行为).#define 无论如何都不应该破坏任何东西.在源代码或 GCC 的 -D_GLIBCXX_USE_NANOSLEEP 标志中.

                  You could do the obvious and simply define it before you include any std:: headers. A bit dirty but will work until GCC fixes it (unless this is intended behavior). The #define shouldn't break anything anyways. Either in source or -D_GLIBCXX_USE_NANOSLEEP flag to GCC.

                  您可能想尝试使用 -std=gnu++0x 而不是 -std=c++0x,因为 gnu++0x 经常会引入这样的内容.

                  You might want to try using -std=gnu++0x rather than -std=c++0x, since gnu++0x often pulls in stuff like this.

                  这篇关于std::this_thread::sleep_for() 和 GCC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)
                    <bdo id='0YXhX'></bdo><ul id='0YXhX'></ul>
                  • <i id='0YXhX'><tr id='0YXhX'><dt id='0YXhX'><q id='0YXhX'><span id='0YXhX'><b id='0YXhX'><form id='0YXhX'><ins id='0YXhX'></ins><ul id='0YXhX'></ul><sub id='0YXhX'></sub></form><legend id='0YXhX'></legend><bdo id='0YXhX'><pre id='0YXhX'><center id='0YXhX'></center></pre></bdo></b><th id='0YXhX'></th></span></q></dt></tr></i><div id='0YXhX'><tfoot id='0YXhX'></tfoot><dl id='0YXhX'><fieldset id='0YXhX'></fieldset></dl></div>

                      <tfoot id='0YXhX'></tfoot>

                        <legend id='0YXhX'><style id='0YXhX'><dir id='0YXhX'><q id='0YXhX'></q></dir></style></legend>
                            <tbody id='0YXhX'></tbody>

                          • <small id='0YXhX'></small><noframes id='0YXhX'>