<string>include results in compilation error

Asked 2 years ago, Updated 2 years ago, 64 views

I tried to use the std:string class on the Arduino Platform in Spresense, and when I tried #include<string>, I encountered a compilation error.

Is the C++ standard library unavailable?

Code:

#include<string>

void setup() {
  // put your setup code here, to runonce:

}

void loop() {
  // put your main code here, to run repeatly:

}

Error message:

Infile included from c:\users\takashi\documents\arduinodata\packages\spresense\tools\gcc-arm-none-eabi\5.4.1\windows\arm-none-eabi\include\c++\5.4.1\bits\stl_algobase.h61:

                 from c:\users\takashi\documents\arduinodata\packages\spresense\tools\gcc-arm-none-eabi\5.4.1\windows\arm-none-eabi\include\c++\5.4.1\bits\char_traces.h:39,

                 from c:\users\takashi\documents\arduinodata\packages\spresense\tools\gcc-arm-none-eabi\5.4.1\windows\arm-none-eabi\include\c++\5.4.1\string:40,

                 from C:\Users\takashi\AppData\Local\Temp\arduino_modified_sketch_278803\sketch_jul17a.ino:1:

c:\users\takashi\documents\arduinodata\packages\spresense\tools\gcc-arm-none-eabi\5.4.1\windows\arm-none-eabi\include\c++\5.4.1\bits\cpp_type_trits.h:168:12:error:redefinition'ofign_construction&starting:

     structure__is_integer<unsigned char>

            ^

c:\users\takashi\documents\arduinodata\packages\spresense\tools\gcc-arm-none-eabi\5.4.1\windows\arm-none-eabi\include\c++\5.4.1\bits\cpp_type_trites.h:147:12:previable_ofignition; construction&starting:

     structure__is_integer<bool>

            ^

(post on Sony developer forum)

spresense

2022-09-30 14:44

5 Answers

Community Bot activated this post and caught my eye, so I gave it a try.

I tried the following code provided in the latest board package (2.3.0) and compiled it without any problems.

#include<string>

void setup() {
  // put your setup code here, to runonce:

}

void loop() {
  // put your main code here, to run repeatly:

}

It seems that you responded at some time.


2022-09-30 14:44

For Arduino, it seems to use String Object.

https://www.arduino.cc/reference/en/language/variables/data-types/stringobject/

I could use this normally.


2022-09-30 14:44

I read the error message.

c:\users\takashi\documents\arduinodata\packages\spresense\tools\gcc-arm-none-eabi\5.4.1\windows\arm-none-eabi\include\c++\5.4.1\bits\cpp_type_trites.h:168:12:error:redefinition' condition' of ___beginner: structure__is_integer

[Direct translation] Error: 'struct std::__is_integer' is redefined.

structure_is_integer<unsigned char>

c:\users\takashi\documents\arduinodata\packages\spresense\tools\gcc-arm-none-eabi\5.4.1\windows\arm-none-eabi\include\c++\5.4.1\bits\cpp_type_trites.h:147:12:error:previous deployment structure__is_integer

[Direct translation] Error: The previous definition of 'struct std::__is_integer' was

structure_is_integer<bool>

==
You're saying it's no good because the definitions of "struct__is_integer<unsigned char>" and "struct_is_integer<bool>" are covered, but if you read it honestly, "unsigned char" and "bool" are different types, so you don't wear them.

I think that it is declared that unsigned char and bool are the same.
In the header file

#defbool unsigned char

or

# undefined charbool

Isn't there a line like this? If you have one, please leave a comment.
Then the error will disappear.


2022-09-30 14:44

It doesn't seem to be a fundamental solution, but based on Fumu7's response
I deleted __is_integer in cpp_type_trats.h and found that
The string was successfully included.
If you don't have anything to do with _is_integer, why don't you try it?

If the library is created, no one else will be able to use it...


2022-09-30 14:44

Arduino has a source extension of ino, but I think you can also use cpp.
Could you write #include to another file with the extension cpp and call it from ino?


2022-09-30 14:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.