【问题标题】:error: 'mutex' does not name a type错误:“互斥”没有命名类型
【发布时间】:2016-07-05 03:02:03
【问题描述】:

当我在 ubuntu 中使用 arm-none-eabi-g++ 工具链尝试以下代码时,我遇到了编译错误:

#include <iostream>  
#include  <thread>    // std::thread    
#include  <mutex>    // std::mutex    
mutex mtx;           // mutex for critical section

int main ()
{
    return 0;
}

编译命令:

arm-none-eabi-g++ -Os -Wall -std=c++11 -fno-rtti -fno-exceptions -c mt.cc

编译错误:

mt.cc:5:1: 错误:'mutex' 没有命名类型 mutex mtx; // 关键部分的互斥锁

^

gcc 版本:

gcc 版本 4.8.4 20140725(发布)[ARM/embedded-4_8-branch 修订版 213147](用于 ARM 嵌入式处理器的 GNU 工具)

【问题讨论】:

  • @venkat 你忘了std::
  • @Idos,不,不是同一个问题。
  • 我确实尝试过 std:: 起初这是我得到的错误“mt.cc:5:1: error: 'mutex' in namespace 'std' does not name a type std: :mutex mtx; // 临界区互斥"

标签: c++ c++11 gcc


【解决方案1】:

你没看错:

#include  <mutex>    // std::mutex    

但是你没有得到正确的代码:

mutex mtx;           // mutex for critical section

应该是std::mutex

【讨论】:

  • 正如我上面提到的,我首先尝试使用 std:: 然后我收到此错误 "mt.cc:5:1: error: 'mutex' in namespace 'std' does not name a type std::mutex mtx; // 临界区的互斥锁 ^ "
  • 在这种情况下,您的 GCC 实现可能不支持该 ARM 平台的 C++11 线程库。
  • arm-none-eabi 表示没有操作系统的系统,只有裸机,所以你没有大部分标准库,所以没有 pthreads(GCC 的 std ::mutex 建立在)之上。
猜你喜欢
  • 2017-11-17
  • 2011-12-10
  • 2013-09-09
  • 2015-12-01
  • 2014-12-16
  • 2016-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多