braydenanderson2014 / C-Arduino-Libraries

This repository contains C++ and Arduino Libraries that are lightweight and easy to use. All libraries were created/mimicked by me and chatgpt.
Apache License 2.0
13 stars 0 forks source link

Compilation error: 'Hashtable' was not declared in this scope #73

Closed huster-songtao closed 5 months ago

huster-songtao commented 5 months ago

Describe the Issue A clear and concise description of what the issue is. FQBN: esp32:esp32:XIAO_ESP32C3 Using board 'XIAO_ESP32C3' from platform in folder: C:\Users\tao\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16 Using core 'esp32' from platform in folder: C:\Users\tao\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16

Library Name and Version: Name: Hashtable Version: Last Version https://github.com/braydenanderson2014/C-Arduino-Libraries/tree/main/lib/Hashtable

Environment:

Library Source: [ -] GitHub

Expected Behavior A clear and concise description of what you expected to happen.

Actual Behavior A clear and concise description of what actually happens.

To Reproduce Steps to reproduce the behavior: 1.open https://github.com/braydenanderson2014/C-Arduino-Libraries/blob/main/lib/Hashtable/examples/Example2/Example2.ino

  1. build
  2. See error

C:\Users\tao\AppData\Local\Temp.arduinoIDE-unsaved2024414-18924-1htn8v6.5f6s\Example2\Example2.ino: In function 'void setup()': C:\Users\tao\AppData\Local\Temp.arduinoIDE-unsaved2024414-18924-1htn8v6.5f6s\Example2\Example2.ino:31:5: error: 'Hashtable' was not declared in this scope Hashtable<String, Person> people; // Create a hashtable with keys of type String and values of type Person ^~~~~ C:\Users\tao\AppData\Local\Temp.arduinoIDE-unsaved2024414-18924-1htn8v6.5f6s\Example2\Example2.ino:31:5: note: suggested alternative: 'Printable' Hashtable<String, Person> people; // Create a hashtable with keys of type String and values of type Person ^~~~~ Printable C:\Users\tao\AppData\Local\Temp.arduinoIDE-unsaved2024414-18924-1htn8v6.5f6s\Example2\Example2.ino:31:21: error: expected primary-expression before ',' token Hashtable<String, Person> people; // Create a hashtable with keys of type String and values of type Person ^ C:\Users\tao\AppData\Local\Temp.arduinoIDE-unsaved2024414-18924-1htn8v6.5f6s\Example2\Example2.ino:31:29: error: expected primary-expression before '>' token Hashtable<String, Person> people; // Create a hashtable with keys of type String and values of type Person ^ C:\Users\tao\AppData\Local\Temp.arduinoIDE-unsaved2024414-18924-1htn8v6.5f6s\Example2\Example2.ino:31:31: error: 'people' was not declared in this scope Hashtable<String, Person> people; // Create a hashtable with keys of type String and values of type Person ^~ C:\Users\tao\AppData\Local\Temp.arduinoIDE-unsaved2024414-18924-1htn8v6.5f6s\Example2\Example2.ino:31:31: note: suggested alternative: 'pipe' Hashtable<String, Person> people; // Create a hashtable with keys of type String and values of type Person ^~ pipe C:\Users\tao\AppData\Local\Temp.arduinoIDE-unsaved2024414-18924-1htn8v6.5f6s\Example2\Example2.ino:53:5: error: 'SimpleVector' was not declared in this scope SimpleVector keys = people.keys(); // Get a vector of all the keys in the hashtable ^~~~ C:\Users\tao\AppData\Local\Temp.arduinoIDE-unsaved2024414-18924-1htn8v6.5f6s\Example2\Example2.ino:53:24: error: expected primary-expression before '>' token SimpleVector keys = people.keys(); // Get a vector of all the keys in the hashtable ^ C:\Users\tao\AppData\Local\Temp.arduinoIDE-unsaved2024414-18924-1htn8v6.5f6s\Example2\Example2.ino:53:26: error: 'keys' was not declared in this scope SimpleVector keys = people.keys(); // Get a vector of all the keys in the hashtable ^~~~ C:\Users\tao\AppData\Local\Temp.arduinoIDE-unsaved2024414-18924-1htn8v6.5f6s\Example2\Example2.ino:53:26: note: suggested alternative: 'gets' SimpleVector keys = people.keys(); // Get a vector of all the keys in the hashtable ^~~~ gets C:\Users\tao\AppData\Local\Temp.arduinoIDE-unsaved2024414-18924-1htn8v6.5f6s\Example2\Example2.ino:54:30: error: unable to deduce 'auto&&' from 'keys' for (const String& key : keys) { // Iterate through the keys, using a range-based for loop... String& is used to avoid copying the key ^~~~

exit status 1

Compilation error: 'Hashtable' was not declared in this scope

Error Message & Code Snippet If applicable, add the error message and the piece of code that causes the issue.


// Your code that triggers the error
Screenshots
![image](https://github.com/braydenanderson2014/C-Arduino-Libraries/assets/94954133/a7de2555-9809-4b86-9e83-f678698b9c9c)

If applicable, add screenshots to help explain your problem.

Additional Context
Add any other context about the problem here.

<!-- End of the issue report template. -->
braydenanderson2014 commented 5 months ago

Thank you for reporting the issue. I will begin looking into the issue and will see what I can do to fix it.

braydenanderson2014 commented 5 months ago

Hello, after some researching and testing I have found that this issue is not related to the code itself. The issue seems to be related to how arduino ide deals with libraries for certain boards. For instance if you set the board type to an arduino uno, the library compiles with no issues. I'm not certain as to why it would be having issues with your board as this library is not platform specific and should work on any board. I'll keep looking around to see if I can find a fix but for now I will be closing the issue. Thank you for bringing this to my attention -Brayden A.

braydenanderson2014 commented 5 months ago

After some research into this issue, I found that esp and arduino boards use different compiler settings which may be your answer to why it's not working. I would make sure that the include directories where the Hashtable.h and SimpleVector.h are being stored are actually being included when the esp board is being compiled. At any rate this is not an issue with my code.

huster-songtao commented 5 months ago

Novice may give up further learning when running the example fails.

Install the lib: SimpleVector, and run the example:Example2 https://github.com/braydenanderson2014/C-Arduino-Libraries/blob/main/lib/SimpleVector/examples/Example2/Example2.ino

image

FQBN: esp32:esp32:XIAO_ESP32C3 Using board 'XIAO_ESP32C3' from platform in folder: C:\Users\tao\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16 Using core 'esp32' from platform in folder: C:\Users\tao\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16

In file included from C:\Users\tao\AppData\Local\Temp.arduinoIDE-unsaved2024420-13868-2nhyid.kgd8d\Example2\Example2.ino:17: d:\Arduino\Sketchbook\libraries\SimpleVector\src/SimpleVector.h: In instantiation of 'T& SimpleVector::get(unsigned int) [with T = String]': C:\Users\tao\AppData\Local\Temp.arduinoIDE-unsaved2024420-13868-2nhyid.kgd8d\Example2\Example2.ino:34:35: required from here d:\Arduino\Sketchbook\libraries\SimpleVector\src/SimpleVector.h:148:20: error: conversion from 'std::nullptr_t' to 'String' is ambiguous return nullptr; // You can handle this error differently if needed ^~~ In file included from C:\Users\tao\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16\cores\esp32/Arduino.h:188, from d:\Arduino\Sketchbook\libraries\SimpleVector\src/SimpleVector.h:4, from C:\Users\tao\AppData\Local\Temp.arduinoIDE-unsaved2024420-13868-2nhyid.kgd8d\Example2\Example2.ino:17: C:\Users\tao\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16\cores\esp32/WString.h:65:9: note: candidate: 'String::String(const FlashStringHelper*)' String(const FlashStringHelper str) : String(reinterpret_cast<const char>(str)) {} ^~ C:\Users\tao\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16\cores\esp32/WString.h:59:9: note: candidate: 'String::String(const char)' String(const char cstr = ""); ^~

Using library SimpleVector at version 1.0.0 in folder: D:\Arduino\Sketchbook\libraries\SimpleVector exit status 1

Compilation error: exit status 1

braydenanderson2014 commented 5 months ago

Hello, I am sorry that my example is not working. As I stated, I test compile and test all code using platformio. Last I checked it was all working which is why I added it to arduino library manager. I will take a look and see if there example needs updating. The examples are not meant to be a code to run. They are just a basic show of how the functions get called.

Judging based off your error output, it looks like you are using an outdated version of SimpleVector. I haven't updated the one on arduino library manager yet but GitHub and Platformio have the most up to date versions. The way I can tell is it shows that line 148 of SimpleVector has an error: "SimpleVector.h:148:20: error: conversion from 'std::nullptr_t' to 'String' is ambiguous return nullptr; // You can handle this error differently if needed ^~~"

In the most up to date version of SimpleVector, line 148 is a closing curly brace to a different function called bulk add. I looked and the version where 148 would have an error was the get function for SimpleVector... in the newer version the get function is in a different place and was overhauled. As soon as I am able I will publish the latest version including an updated example (if I find the example is not working). This set of libraries was primarily meant for arduino but theoretically would work on any device. But I have not tested on any other device since I do not own an esp.

I do apologize that you are having issues with my code examples but please keep in mind I developed all the libraries available by myself in my free time. They are also all free and open source which means anyone also has the ability to adjust code as well. All the code I have tested worked just fine using Platformio and Wokwi simulator for the few I tested there. I highly recommend using Platformio since that is the most up to date code since it's easier to push an update.

huster-songtao commented 5 months ago

many thanks.