Error : 'str1' does not name a type

Hello!
We are working on adding Arduino 3rd party support to a RISC-V based board SHAKTI (Parashu). While adding the String Library ( WString.h) and testing. Whenever a String object is declared inside setup() or loop() function it works fine, but when I declare a String object outside that in the editor I end up with either getting a string printed (null) or a error as per below.

Case when the code runs :

//CASE 1
void setup() {
  String str1 = "abcde1234";
  Serial.println(str1);
}
void loop() {
}

Output:

abcde1234

When I declare the String object outside the function

//CASE 2
String str1 = "abcde1234";
void setup() {
 Serial.println(str1);
}
void loop() {
}

Output:

(null)

Incase I just declare the String object and try to set value or string after

//CASE 3
String str1;
str1 = "abcde1234";
void setup() {

  Serial.println(str1);
}

void loop() {
}

I encounter a error saying "str1 does not name a type"

/home/sambhav/.arduino15/packages/shakti/tools/riscv32-unknown-elf-gcc/1.0/bin/riscv32-unknown-elf-g++ -c -march=rv32imac -w -fpeel-loops -mcmodel=medany -ffreestanding -nostdinc++ -fno-builtin-printf -fdata-sections -fpermissive -Wall -fno-rtti -fno-exceptions -I/home/sambhav/.arduino15/packages/shakti/hardware/riscv/1.0.0/system/include -I/home/sambhav/.arduino15/packages/shakti/hardware/riscv/1.0.0/system -I/home/sambhav/.arduino15/packages/shakti/hardware/riscv/1.0.0/cores/arduino/shakti-sdk/bsp/include -I/home/sambhav/.arduino15/packages/shakti/hardware/riscv/1.0.0/cores/arduino/shakti-sdk/bsp/drivers -I/home/sambhav/.arduino15/packages/shakti/hardware/riscv/1.0.0/cores/arduino/shakti-sdk/bsp/third_party/parashu -I/home/sambhav/.arduino15/packages/shakti/hardware/riscv/1.0.0/cores/arduino/shakti-sdk/bsp/libs -I/home/sambhav/.arduino15/packages/shakti/hardware/riscv/1.0.0/cores/arduino/shakti-sdk/bsp/third_party/parashu -g -include sys/cdefs.h -g -DARDUINO=10812 -DF_CPU=-DSHAKTI_ECLS -I/home/sambhav/.arduino15/packages/shakti/hardware/riscv/1.0.0/cores/arduino -I/home/sambhav/.arduino15/packages/shakti/hardware/riscv/1.0.0/variants/parashu /tmp/arduino_build_651804/sketch/test_string1.ino.cpp -o /tmp/arduino_build_651804/sketch/test_string1.ino.cpp.o
test_string1:2:1: error: 'str1' does not name a type
 str1 = "abcde1234";
 ^~~~
exit status 1
'str1' does not name a type

I am attaching the respective code as well below to the gitlab repository
WString.cpp
WString.h
It would be quite helpful to understand what the issue might be or normally how to tackle this issue. The compiler used here if riscv32-unkown-elf-g++
P.S:
The link to the arduino 3rd party repository is here if anyone is interested to try it out in their IDE as the installation steps are provided in the README

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.