Declared okapi variables in hedears file

Hi guys, i using the okapi library from pros, to filter readings of my sensors, and i dont have any problems to using that fuction cause a i read the documentation.

I used to organize my project creating headears files and cpp files, for example i make a headear file call it, “Motors_sensors.h”

For example inside that hedear file i put:
extern pros::Motor Leftmotor;

And i create a cpp file call it “Motors_sensors.cpp” and i put:
pros::Motor Leftmotor (port, gearing, reverse?, encoder_units);

With that i can make a reference to the motor in any other file, and that is helpful for fuctions or another things.

So i want to make the same thing with okapi library, but i have an error, i tried to do this think and didnt work .

In a hedear file:
extern okapi::EMafilter ema_filter;

In a cpp file:
okapi::EMAfilter ema_filter(.25);

but i have an error, do you know how i can fix this, i really like be able to use my filter variable in another files

What is the error? If it’s about a variable already declared or duplicate variable (I forget the error exactly), try putting static in front of the declaration in the C file. I believe that resolved it when we tried a similar approach.

did you include the okapi api or main.h in the file? The file needs to know where the variable is declared in order to compile.

Well i can fixed it, in the hedear file i included the library of okapi, and i declared my filter with “extern”
And in the cpp file i put the all definition of the filter.

I dont know how it work, cause normally when i create header i put guards and in the main.h i include my headers files, so when i make my cpp files i put #include “main.h”.

And always watch the okapi library is included in the main.h