Compiler Error with Library

I created a .h, .cpp, keywords.txt, and .ino files that compile and work as expected. Then I created the files that are attached. I have a directory called Fdr that contains the .h, .cpp, and keywords.txt files. It is within my libraries directory just like the files that work.

The compiler says:
...
Compiling sketch...
"C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.42.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=10813 -DARDUINO_AVR_PROMICRO -DARDUINO_ARCH_AVR -DUSB_VID=0x1b4f -DUSB_PID=0x9206 "-DUSB_MANUFACTURER="Unknown"" "-DUSB_PRODUCT="SparkFun Pro Micro"" "-IC:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.42.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\cores\arduino" "-IC:\Users\rgspa\Documents\ArduinoData\packages\SparkFun\hardware\avr\1.1.13\variants\promicro" "-IC:\Users\Owner\Arduino\arduinosketchfolder\libraries\Fdr" "-IC:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.42.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\Wire\src" "C:\Users\rgspa\AppData\Local\Temp\arduino_build_109682\sketch\FlightDataRecorder16.ino.cpp" -o "C:\Users\rgspa\AppData\Local\Temp\arduino_build_109682\sketch\FlightDataRecorder16.ino.cpp.o"
C:\Users\Owner\Documents\Rick\Teaching\Glendale Community College\balloon class\Arduino\SOFTWARE\FlightDataRecorder16\FlightDataRecorder16.ino: In function 'void loop()':
FlightDataRecorder16:37:3: error: 'fdr' was not declared in this scope
** fdr.Pointers(PointerArray);**//send pointer array to the library
^~~
C:\Users\Owner\Documents\Rick\Teaching\Glendale Community College\balloon class\Arduino\SOFTWARE\FlightDataRecorder16\FlightDataRecorder16.ino:37:3: note: suggested alternative: 'Fdr'
fdr.Pointers(PointerArray);//send pointer array to the library
^~~
Fdr
Using library Fdr in folder: C:\Users\Owner\Arduino\arduinosketchfolder\libraries\Fdr (legacy)
Using library Wire at version 1.0 in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.42.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\Wire
exit status 1
'fdr' was not declared in this scope

I have repeatedly compared my working files to the attached files and cannot see what I've done wrong. Your help would be greatly appreciated!

Rick

FlightDataRecorder16.ino (1.74 KB)

Fdr.cpp (338 KB)

Fdr.h (7.82 KB)

keywords.txt (31 Bytes)

You instantiate an object called Fdr - then try to access it as fdr

In the example that works, it was lower case even though that made no sense to me. I changed fdr to Fdr and got:

C:\Users\Owner\Documents\Rick\Teaching\Glendale Community College\balloon class\Arduino\SOFTWARE\FlightDataRecorder16\FlightDataRecorder16.ino: In function 'void setup()':
FlightDataRecorder16:30:6: error: request for member 'Pointers' in 'Fdr', which is of non-class type 'Fdr()'
** Fdr.Pointers(PointerArray);//send pointer array to the library**
^~~~~~~~
Using library Fdr in folder: C:\Users\Owner\Arduino\arduinosketchfolder\libraries\Fdr (legacy)
Using library Wire at version 1.0 in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.42.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\Wire
exit status 1
request for member 'Pointers' in 'Fdr', which is of non-class type 'Fdr()'

Rick

Fdr.cpp (338 KB)

Fdr.h (7.82 KB)

keywords.txt (31 Bytes)

FlightDataRecorder16.ino (1.67 KB)

//Fdr Fdr(); Change to.. -->> Fdr ourFdr(); Maybe?

-jim lee

Jim,

If I comment out Fdr.Pointers(PointerArray) or fdr.Pointers(PointerArray), the compiler errors go away so I think Fdr Fdr() is not the problem. Note that I have Fdr Fdr() near the top of the file and have it commented out at line 25.

Rick

Would you try doing this?

int int = 4;

Because to the compiler that's pretty much exactly what

Fdr Fdr();

is.

You only get to use a name once. You called the class Fdr so objects you create using that class can not be called Fdr.

-jim lee

jimLee:
//Fdr Fdr(); Change to.. -->> Fdr ourFdr(); Maybe?

Close, but not quite. The compiler would interpret "Fdr ourFdr();" as a prototype for a function named "ourFdr" that takes no arguments and returns an object of the "Fdr" class.

If the constructor for the "Fdr" class takes no arguments, use ""Fdr ourFdr;"

Yes, it bothered me a lot to use that syntax. But if you go to Arduino - LibraryTutorial you will see

#include "Arduino.h"

class Morse
{
public:
Morse(int pin);
void dot();
void dash();
private:
int _pin;
};

#endif

Morse Morse(int pin) sets up the environment for the library. I ran this code and it does work. Changing the name causes compiler errors.

Rick

"Morse(int pin);" is the prototype for the Morse class constructor.

Regardless, you can't give an object the same name as the class and stubbornly refusing to believe that will not change the fact.

I'm sorry if I am coming across as stubborn. My goal is to get my library to work.

Rick

rgsparber:
My goal is to get my library to work.

That seems to be a huge amount of code. Did you build the library step-by-step, adding one function at a time then compiled and tested it? If so, it should be pretty simple to go back to the last working version and figure out what you broke with the most recent addition.

However, if you just plopped it all down at once, then, IMO, it's going to be more difficult. In that case, I'd start over with a completely blank project. Add in one feature at a time. Then, compile and integration test it. Only move on to the next feature when the previous one is working.

I'd also keep all the files (.ino, .h, cpp) in one project folder until everything is working. Then you can more the "library" to ".../sketchbook/libraries". Although, this thing seems so specialized, do you really think it will be integrated into more than one project? If not, there's really no point in moving some of it to the libraries folder.

gfvalvo:
Close, but not quite. The compiler would interpret "Fdr ourFdr();" as a prototype for a function named "ourFdr" that takes no arguments and returns an object of the "Fdr" class.

If the constructor for the "Fdr" class takes no arguments, use ""Fdr ourFdr;"

Oh yeah, missed that.

-jim led

I started with my program that ran with no known bugs and needed to move it into a library. I now see that doing it in one step was bad news. I did comment out and #ifdef out all of the code I added but must have missed something since it won't compile without errors.

Time to start over.

Thanks for your help,

Rick
PS: this is only about half of the code. The other half is in another Pro Micro dedicated to an Iridium modem.

" Although, this thing seems so specialized, do you really think it will be integrated into more than one project? If not, there's really no point in moving some of it to the libraries folder."

My problem is that students hack into my code and break it. Placing this code into a library will greatly reduce and maybe eliminate this hacking. They are not being malicious, just confused.

The students need to add to the calling program, just not to my functions. I plan to give them a very small file that they can modify plus a list of the functions they can call.

Is there a simpler way to do this?

Rick

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