错误:'constexpr'未命名类型 m- Arduino IDE
error: 'constexpr' does not name a type m- arduino ide
我正在尝试使用Arduino 1.0.5-r2 IDE编译此c++代码
#include <cstdint>
#include "mcal_reg.h"
class led
{
public:
// Use convenient class-specific typedefs.
typedef std::uint8_t port_type;
typedef std::uint8_t bval_type;
// The led class constructor.
led(const port_type p,
const bval_type b) : port(p),
bval(b)
{
// Set the port pin to low.
*reinterpret_cast<volatile bval_type*>(port)
&= static_cast<bval_type>(~bval);
// Set the port pin to output.
*reinterpret_cast<volatile bval_type*>(port - 1U)
|= bval;
}
void toggle() const
{
// Toggle the LED via direct memory access.
*reinterpret_cast<volatile bval_type*>(port)
^= bval;
}
private:
// Private member variables of the class.
const port_type port;
const bval_type bval;
};
namespace
{
// Create led_b5 on portb.5.
const led led_b5
{
mcal::reg::portb,
mcal::reg::bval5
};
}
int main()
{
// Toggle led_b5 in a loop forever.
for(;;)
{
led_b5.toggle();
}
包含文件mcal_reg.h如下:
#ifndef _MCAL_REG_2011_11_04_H_
#define _MCAL_REG_2011_11_04_H_
#include <cstdint>
namespace mcal
{
namespace reg
{
constexpr std::uint8_t portb = 0x25U;
constexpr std::uint8_t bval0 = 0x01U;
constexpr std::uint8_t bval1 = 0x01U << 1U;
constexpr std::uint8_t bval2 = 0x01U << 2U;
constexpr std::uint8_t bval3 = 0x01U << 3U;
constexpr std::uint8_t bval4 = 0x01U << 4U;
constexpr std::uint8_t bval5 = 0x01U << 5U;
constexpr std::uint8_t bval6 = 0x01U << 6U;
constexpr std::uint8_t bval7 = 0x01U << 7U;
}
}
#endif // _MCAL_REGISTERS_2011_11_04_H_
}
尝试编译会导致以下编译错误:
mcal_reg.h:17: error: 'constexpr' does not name a type
指这一行:constexpr std::uint8_t portb = 0x25U;
我已经在我的库文件夹中设置了一个mcal_reg目录,其中包含mcal_reg.h文件。这是我的第一个Arduino项目,我正在编写一个程序,以闪现到一个独立的AVR芯片。但是我不能编译这个程序。我的系统是Windows 7。我只安装了Arduino IDE自带的软件。(没有单独的GNU, Ms Visual Studio…等)请帮助。
要使用像constexpr这样的c++ 11特性,您需要将IDE更新到当前的测试版(http://arduino.cc/en/main/software#toc3)。然后通过编译器标志-std=c++11
启用c++ 11支持。
要添加编译器标志,请找到正确的platform.txt(见这里)和然后在
中添加/change## Compiler global definitions
compiler.path={runtime.ide.path}/tools/avr/bin/
compiler.c.cmd=avr-gcc
compiler.c.flags=-c -g -Os -w -ffunction-sections -fdata-sections -MMD -std=c++11
相关文章:
- Arduino IDE 中使用 strncmp 函数时出错
- Arduino IDE 错误 - 无法找到数字文字运算符"运算符""f900ff"
- Arduino IDE中自定义库类的.h文件编译错误的原因是什么
- 无法ESP8266连接到 Arduino IDE
- 使用Arduino IDE的构造函数的未定义参考错误
- 如何在arduino ide中修复"undefined reference to:",尝试使用googletest
- 将 API 链接消息解析为 C (Arduino IDE) 中的服务器
- 为什么我的串行串行在Arduino IDE上通过串行显示器进行两次打印
- 覆盆子Pi(QT C )和Arduino(Arduino IDE)之间的通信
- Arduino IDE告诉我找不到字符串文字运算符“运算符”“DRIVE”
- Matlab Coder and Arduino IDE emxCreateWrapper_real_T
- 从Arduino IDE中的类中读取和写入值
- 用于 2 辆 DC 汽车的 arduino IDE 代码,带有 L298 和超声波和蓝牙控制与安卓
- 使用Arduino IDE编程是否适合商业产品
- Arduino IDE - 按下按钮时停止重复'Serial.println'
- 如何为 Arduino IDE 安装 openCV 库
- arduino ide 中缺少端口选项
- Arduino IDE编译器错误多重定义
- 在 Arduino IDE 上导入库时出错
- Libraries in Arduino IDE 1.0