SML需要C++14支持。

huangapple go评论68阅读模式
英文:

SML requires C++14 support

问题

我刚开始学习Adruino,并想在其中使用[boost sml库](https://github.com/boost-ext/sml/tree/master)。我下载了sml.hpp文件,并通过库管理器将其添加到了Arduino项目中。但当我尝试运行文件时,我收到了以下错误消息:

error: #error "[Boost::ext].SML需要支持C++14 (Clang-3.4+,GCC-5.1+,MSVC-2015+)"
 #error "[Boost::ext].SML需要支持C++14 (Clang-3.4+,GCC-5.1+,MSVC-2015+)"

我的Arduino配置:

{
    "board": "arduino:avr:micro",
    "programmer": "avrisp",
    "port": "/dev/ttyACM0",
    "output": "../build",
    "sketch": "test.ino",
    "intelliSenseGen": "global"
}

我使用的是avr-gcc (gcc版本 7.3.0 (GCC),所以应该支持c++14?)。
我在c_cpp_properties.json文件中将c++版本更改为了14:

"configurations": [
    {
        "name": "Arduino",
        "compilerPath": "home/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++",
        "compilerArgs": [
            "-w",
            "-std=c++14",
            "-fpermissive",
            "-fno-exceptions",
            "-ffunction-sections",
            "-fdata-sections",
            "-fno-threadsafe-statics",
            "-Wno-error=narrowing"
        ],
        "intelliSenseMode": "gcc-x64",
        "includePath": [
            "home/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino",
            "home/.arduino15/packages/arduino/hardware/avr/1.8.6/variants/micro",
            "/home/Arduino/libraries/src",
            "/home/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/lib/gcc/avr/7.3.0/include",
            "/home/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/lib/gcc/avr/7.3.0/include-fixed",
            "/home/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/avr/include"
        ],
        "forcedInclude": [
            "/home/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/Arduino.h"
        ],
        "cStandard": "c11",
        "cppStandard": "c++14",
        "defines": [
            ...
            "__cplusplus=201402L",
            ...
        ]
    }
]

错误发生在sml.hpp文件中:

#if (__cplusplus < 201305L && _MSC_VER < 1900)
#error "[Boost::ext].SML需要支持C++14 (Clang-3.4+,GCC-5.1+,MSVC-2015+)" 
#else

任何帮助都将不胜感激。

最好的祝愿

编辑:

我的avr-g++的tasks.json文件:

"version": "2.0.0",
"tasks": [
    {
        "type": "cppbuild",
        "label": "C/C++: avr-g++构建活动文件",
        "command": "/home/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++",
        "args": [
            "-fdiagnostics-color=always",
            "-g",
            "${file}",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}",
            "-w"

<details>
<summary>英文:</summary>

I am starting out with Adruino and wanted to use the [boost sml library](https://github.com/boost-ext/sml/tree/master) on it. I downloaded the sml.hpp file and added it to arduino project using the library manager. But when i try to run the file I get the following **error message:**

error: #error "[Boost::ext].SML requires C++14 support (Clang-3.4+, GCC-5.1+, MSVC-2015+)"
#error "[Boost::ext].SML requires C++14 support (Clang-3.4+, GCC-5.1+, MSVC-2015+)"

**My Arduino:**

{
"board": "arduino:avr:micro",
"programmer": "avrisp",
"port": "/dev/ttyACM0",
"output": "../build",
"sketch": "test.ino",
"intelliSenseGen": "global"
}

I am using avr-gcc (gcc version 7.3.0 (GCC) so it should support c++14?)
I changed the version of c++ to 14 in the **c_cpp_properties.json**

"configurations": [
{
"name": "Arduino",
"compilerPath": "home/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++",
"compilerArgs": [
"-w",
"-std=c++14",
"-fpermissive",
"-fno-exceptions",
"-ffunction-sections",
"-fdata-sections",
"-fno-threadsafe-statics",
"-Wno-error=narrowing"
],
"intelliSenseMode": "gcc-x64",
"includePath": [
"home/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino",
"home/.arduino15/packages/arduino/hardware/avr/1.8.6/variants/micro",
"/home/Arduino/libraries/src",
"/home/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/lib/gcc/avr/7.3.0/include",
"/home/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/lib/gcc/avr/7.3.0/include-fixed",
"/home/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/avr/include"
],
"forcedInclude": [
"/home/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/Arduino.h"
],
"cStandard": "c11",
"cppStandard": "c++14",
"defines": [
...
"__cplusplus=201402L",
...


The error gets thrown in the sml.hpp file 

#if (__cplusplus < 201305L && _MSC_VER < 1900)
#error "[Boost::ext].SML requires C++14 support (Clang-3.4+, GCC-5.1+, MSVC-2015+)"
#else


Any help is appreciated. 
Best regards
**Edit**
My tasks.json for avr-g++ :

"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: avr-g++ build active file",
"command": "/home/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-w",
"-std=c++14",
"-fpermissive",
"-fno-exceptions",
"-ffunction-sections",
"-fdata-sections",
"-fno-threadsafe-statics",
"-Wno-error=narrowing"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /home/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-g++"
}
]
}


</details>
# 答案1
**得分**: 2
{
"board": "arduino:avr:micro",
"programmer": "avrisp",
"port": "/dev/ttyACM0",
"output": "../build",
"sketch": "test.ino",
"intelliSenseGen": "global",
"buildPreferences": [
["build.extra_flags", "-std=c++14"]
]
}
<details>
<summary>英文:</summary>
After looking at the option. I found the build preferences:
I added following flag to the arduino.json:
{
&quot;board&quot;: &quot;arduino:avr:micro&quot;,
&quot;programmer&quot;: &quot;avrisp&quot;,
&quot;port&quot;: &quot;/dev/ttyACM0&quot;,
&quot;output&quot;: &quot;../build&quot;,
&quot;sketch&quot;: &quot;test.ino&quot;,
&quot;intelliSenseGen&quot;: &quot;global&quot;,
&quot;buildPreferences&quot;: [
[&quot;build.extra_flags&quot;, &quot;-std=c++14&quot;]
]
</details>

huangapple
  • 本文由 发表于 2023年7月18日 03:46:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76707665.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定