Error including "tracker.h"

I am trying to access the Tracker::instance() (to use the location object)

but got an error the moment i added #include "tracker.h" to my own header file.

> Executing task in folder sts-tracker-firmware: make -f '/Users/kennethlimcp/.particle/toolchains/buildscripts/1.9.2/Makefile' compile-user -s <


:::: COMPILING APPLICATION

Creating /path/target/1.5.4-rc.1/tracker/platform_user_ram.ld ...
In file included from /path/lib/config-service/src/config_service.h:21:0,
                 from /path//src/tracker.h:25,
                 from /path//src/r.h:9,
                 from /path//src/r.cpp:1:
/path/lib/config-service/src/config_service_nodes.h:148:37: error: macro "max" requires 2 arguments, but only 1 given
         ConfigInt &max(int32_t value) {range_max = value; return *this;}
                                     ^
/path/lib/config-service/src/config_service_nodes.h:149:37: error: macro "min" requires 2 arguments, but only 1 given
         ConfigInt &min(int32_t value) {range_min = value; return *this;}
                                     ^
/path/lib/config-service/src/config_service_nodes.h:183:38: error: macro "max" requires 2 arguments, but only 1 given
         ConfigFloat &max(double value) {range_max = value; return *this;}
                                      ^
/path/lib/config-service/src/config_service_nodes.h:184:38: error: macro "min" requires 2 arguments, but only 1 given
         ConfigFloat &min(double value) {range_min = value; return *this;}
                                      ^
In file included from ./inc/Arduino.h:27:0,
                 from /path/lib/MCP_CAN_RK/src/mcp_can_dfs.h:27,
                 from /path/lib/MCP_CAN_RK/src/mcp_can.h:27,
                 from /path//src/r.h:6,
                 from /path//src/r.cpp:1:
/Users/kennethlimcp/.particle/toolchains/gcc-arm/5.3.1/arm-none-eabi/include/c++/5.3.1/bits/stl_vector.h: In member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::_M_check_len(std::vector<_Tp, _Alloc>::size_type, const char*) const':
../wiring/inc/spark_wiring_arduino_constants.h:111:18: error: expected unqualified-id before '(' token
 #define max(a,b) ((a)>(b)?(a):(b))
                  ^
/Users/kennethlimcp/.particle/toolchains/gcc-arm/5.3.1/arm-none-eabi/include/c++/5.3.1/bits/stl_bvector.h: In member function 'std::vector<bool, _Alloc>::size_type std::vector<bool, _Alloc>::_M_check_len(std::vector<bool, _Alloc>::size_type, const char*) cons':
../wiring/inc/spark_wiring_arduino_constants.h:111:18: error: expected unqualified-id before '(' token
 #define max(a,b) ((a)>(b)?(a):(b))
                  ^
In file included from /path/lib/config-service/src/config_service.h:21:0,
                 from /path//src/tracker.h:25,
                 from /path//src/r.h:9,
                 from /path//src/r.cpp:1:
/path/lib/config-service/src/config_service_nodes.h: At global scope:
/path/lib/config-service/src/config_service_nodes.h:148:72: error: expected ';' at end of member declaration
         ConfigInt &max(int32_t value) {range_max = value; return *this;}
                                                                        ^
/path/lib/config-service/src/config_service_nodes.h:149:72: error: expected ';' at end of member declaration
         ConfigInt &min(int32_t value) {range_min = value; return *this;}
                                                                        ^
/path/lib/config-service/src/config_service_nodes.h:148:52: error: 'value' was not declared in this scope
         ConfigInt &max(int32_t value) {range_max = value; return *this;}
                                                    ^
/path/lib/config-service/src/config_service_nodes.h:148:57: error: expected '}' before ';' token
         ConfigInt &max(int32_t value) {range_max = value; return *this;}
                                                         ^
/path/lib/config-service/src/config_service_nodes.h:148:57: error: invalid initialization of non-const reference of type 'ConfigInt&' from an rvalue of type '<brace-enclosed initializer list>'
/path/lib/config-service/src/config_service_nodes.h:148:57: error: expected ';' before ';' token
/path/lib/config-service/src/config_service_nodes.h:149:52: error: 'value' was not declared in this scope
         ConfigInt &min(int32_t value) {range_min = value; return *this;}
                                                    ^
/path/lib/config-service/src/config_service_nodes.h:149:57: error: expected '}' before ';' token
         ConfigInt &min(int32_t value) {range_min = value; return *this;}
                                                         ^
/path/lib/config-service/src/config_service_nodes.h:149:57: error: invalid initialization of non-const reference of type 'ConfigInt&' from an rvalue of type '<brace-enclosed initializer list>'
/path/lib/config-service/src/config_service_nodes.h:149:57: error: expected ';' before ';' token
/path/lib/config-service/src/config_service_nodes.h:183:73: error: expected ';' at end of member declaration
         ConfigFloat &max(double value) {range_max = value; return *this;}
                                                                         ^
/path/lib/config-service/src/config_service_nodes.h:184:73: error: expected ';' at end of member declaration
         ConfigFloat &min(double value) {range_min = value; return *this;}
                                                                         ^
/path/lib/config-service/src/config_service_nodes.h:183:53: error: 'value' was not declared in this scope
         ConfigFloat &max(double value) {range_max = value; return *this;}
                                                     ^
/path/lib/config-service/src/config_service_nodes.h:183:58: error: expected '}' before ';' token
         ConfigFloat &max(double value) {range_max = value; return *this;}
                                                          ^
/path/lib/config-service/src/config_service_nodes.h:183:58: error: invalid initialization of non-const reference of type 'ConfigFloat&' from an rvalue of type '<brace-enclosed initializer list>'
/path/lib/config-service/src/config_service_nodes.h:183:58: error: expected ';' before ';' token
/patg/lib/config-service/src/config_service_nodes.h:184:53: error: 'value' was not declared in this scope
         ConfigFloat &min(double value) {range_min = value; return *this;}
                                                     ^
/path/lib/config-service/src/config_service_nodes.h:184:58: error: expected '}' before ';' token
         ConfigFloat &min(double value) {range_min = value; return *this;}
                                                          ^
/path/lib/config-service/src/config_service_nodes.h:184:58: error: invalid initialization of non-const reference of type 'ConfigFloat&' from an rvalue of type '<brace-enclosed initializer list>'
/path/lib/config-service/src/config_service_nodes.h:184:58: error: expected ';' before ';' token
make[3]: *** [../build/target/user/platform-26-m/firmware/src/r.o] Error 1
make[2]: *** [user] Error 2
make[1]: *** [modules/tracker/user-part] Error 2
make: *** [compile-user] Error 2
The terminal process "/bin/bash '-c', 'make -f '/Users/kennethlimcp/.particle/toolchains/buildscripts/1.9.2/Makefile' compile-user -s'" terminated with exit code: 2.

Press any key to close the terminal.

Any idea why? Adding #include "tracker.h" to main.cpp` works fine…

Removing the #include tracker.h in my header file allows the firmware to compile without issues.

@kennethlimcp, do you have the Tracker_Edge library copied to your build folder? It is a self-contained “package” and I git-cloned it to a folder and use CLI to compile it.

Yes. i did. Using it fine with:

main.cpp:

#include "tracker.h"

void setup() {
  Tracker::instance().init();
  Tracker::instance().location.regLocGenCallback(locationGenerationCallback);
}

void loop(){
  Tracker::instance().loop();
}

^^^ this compiles and work well.

But if you have a test.h file and you do:

#include tracker.h"

The errors will start to pop up.

@kennethlimcp, test.h? Do you mean you added separate test.h/test.cpp files and want to include them? I simply modified the main.cpp file and pulled in extra libraries like Adafruit_BME280_RK. I would do the include in main.cpp AFTER the 'tracker.h` include.

yes so my directory looks like this:

I want to access the Tracker::instance() in my own class defined in test.h but the errors appeared when adding #include "tracker".h in test.h

├── src
│   ├── gnss_led.cpp
│   ├── gnss_led.h
│   ├── main.cpp
│   ├── motion_service.cpp
│   ├── motion_service.h
│   ├── test.cpp
│   ├── test.h
│   ├── temperature.cpp
│   ├── temperature.h
│   ├── tracker.cpp
│   ├── tracker.h
│   ├── tracker_cellular.cpp
│   ├── tracker_cellular.h
│   ├── tracker_config.h
│   ├── tracker_location.cpp
│   ├── tracker_location.h
│   ├── tracker_motion.cpp
│   ├── tracker_motion.h
│   ├── tracker_rgb.cpp
│   ├── tracker_rgb.h
│   ├── tracker_shipping.cpp
│   └── tracker_shipping.h
└── target

@kennethlimcp, can you share your code for the test files and I’ll try it on my end.

I believe you are getting this error because you’re including “mcp_can.h” which includes <Arduino.h> which enables Arduino compatibility mode, which defines macros for min() and max(), which are a horrible idea because you can’t name a method min or max if you do that. The config service does that.

Try including tracker.h first.

It that doesn’t fix it, after including mcp_can.h

#undef min
#undef max

Works great thanks @rickkas7!