Page 1 of 1

C++: Cannot find preferences library

Posted: Thu Aug 15, 2019 12:37 pm
by kmn08_
I'm new to C++, and trying to write a class.

This class uses the Preferences library imported with #include <Preferences.h> as visible at the top

The issue is that I'm getting error messages when trying to use it in the .h file.

I've tried moving it to main, the errors went away and the Parameters object was successfully created after a test run.

I've been researching the error in vain, no club how to fix this ...

The class code (snippet of the header file):

Code: Select all

    #ifndef PHX_WIFI
    #define PHX_WIFI
    
    #include <Arduino.h>
    #include <Preferences.h>
    
    
    #include "WiFiConfig.h"
    
    class wifi {
    
        Preferences preferences;
    
        std::string preferencesNamespace = "WiFiConfig";
        std::string preferencesKey_SSID = "SSID";
        std::string preferencesKey_Password = "password";
    
        public:
        
        WiFiConfig getStoredConfig(void);  
    
    
    } ;
    
    #endif

The error in a screenshot:
Screen Shot 2019-08-15 at 1.38.26 PM.png
Screen Shot 2019-08-15 at 1.38.26 PM.png (446.27 KiB) Viewed 2913 times

Code structure :

Code: Select all

    src
    |___main.cpp
    |___PHX/
        |___PHX.h
        |___wifi.h
        |___wifi.cpp
       
contents of PHX.h:

Code: Select all


    namespace PHX
    {
        
        #include "wifi.h"
        #include "WiFiConfig.h"
    
    } // namespace PHX
       
When used in main.cpp, works without problem :

Screen Shot 2019-08-15 at 1.45.06 PM.png
Screen Shot 2019-08-15 at 1.45.06 PM.png (310.81 KiB) Viewed 2913 times

Re: C++: Cannot find preferences library

Posted: Fri Aug 16, 2019 8:34 am
by boarchuz
It's because you're in the PHX namespace there. Try "::Preferences preferences;"