Trouble compiling due to variable name interference in the gcc-arm toolchain

I was just trying to compile a very basic example using @rickkas7 MCP79410RK library for the M SoM (deviceOS@5.8.0) and ran into issues due to the internal naming of log for the static Logger. Specifically, the error is:

Executing task: make -f '/Users/dhhagan/.particle/toolchains/buildscripts/1.15.0/Makefile' compile-user -s 


:::: COMPILING APPLICATION

Creating /Users/dhhagan/Documents/github/products/MOD-X/fw-mod-x/fw-mod-x/target/5.8.0/msom/memory_platform_user.ld ...
/Users/dhhagan/Documents/github/products/MOD-X/fw-mod-x/fw-mod-x/lib/MCP79410RK/src/MCP79410RK.cpp:3:18: error: 'spark::Logger log' redeclared as different kind of entity
    3 | static Logger log("app.rtc");
      |                  ^
In file included from /Users/dhhagan/.particle/toolchains/gcc-arm/10.2.1/arm-none-eabi/include/c++/10.2.1/cmath:45,
                 from ../wiring/inc/spark_wiring_print.h:38,
                 from ../wiring/inc/spark_wiring_string.h:34,
                 from ../wiring/inc/spark_wiring_stream.h:30,
                 from ../wiring/inc/spark_wiring.h:40,
                 from ./inc/application.h:42,
                 from ./inc/Particle.h:5,
                 from /Users/dhhagan/Documents/github/products/MOD-X/fw-mod-x/fw-mod-x/lib/MCP79410RK/src/MCP79410RK.h:4,
                 from /Users/dhhagan/Documents/github/products/MOD-X/fw-mod-x/fw-mod-x/lib/MCP79410RK/src/MCP79410RK.cpp:1:
/Users/dhhagan/.particle/toolchains/gcc-arm/10.2.1/arm-none-eabi/include/math.h:109:15: note: previous declaration 'double log(double)'
  109 | extern double log (double);
      |               ^~~
/Users/dhhagan/Documents/github/products/MOD-X/fw-mod-x/fw-mod-x/lib/MCP79410RK/src/MCP79410RK.cpp: In member function 'void MCP79410::setup()':
/Users/dhhagan/Documents/github/products/MOD-X/fw-mod-x/fw-mod-x/lib/MCP79410RK/src/MCP79410RK.cpp:403:9: error: request for member 'info' in 'log', which is of non-class type 'double(double)'
  403 |     log.info("set Time from RTC %s", Time.format(rtcTime, TIME_FORMAT_DEFAULT).c_str());
      |         ^~~~
/Users/dhhagan/Documents/github/products/MOD-X/fw-mod-x/fw-mod-x/lib/MCP79410RK/src/MCP79410RK.cpp: In member function 'bool MCP79410::setRTCFromCloud()':
/Users/dhhagan/Documents/github/products/MOD-X/fw-mod-x/fw-mod-x/lib/MCP79410RK/src/MCP79410RK.cpp:436:7: error: request for member 'info' in 'log', which is of non-class type 'double(double)'
  436 |   log.info("set RTC from cloud %s", Time.format(now, TIME_FORMAT_DEFAULT).c_str());
      |       ^~~~
/Users/dhhagan/Documents/github/products/MOD-X/fw-mod-x/fw-mod-x/lib/MCP79410RK/src/MCP79410RK.cpp:439:7: error: request for member 'info' in 'log', which is of non-class type 'double(double)'
  439 |   log.info("cloud time not valid");
      |       ^~~~
/Users/dhhagan/Documents/github/products/MOD-X/fw-mod-x/fw-mod-x/lib/MCP79410RK/src/MCP79410RK.cpp: In member function 'int MCP79410::deviceRead(uint8_t, uint8_t, uint8_t*, size_t) const':
/Users/dhhagan/Documents/github/products/MOD-X/fw-mod-x/fw-mod-x/lib/MCP79410RK/src/MCP79410RK.cpp:784:8: error: request for member 'info' in 'log', which is of non-class type 'double(double)'
  784 |    log.info("deviceRead failed stat=%d", stat);
      |        ^~~~
/Users/dhhagan/Documents/github/products/MOD-X/fw-mod-x/fw-mod-x/lib/MCP79410RK/src/MCP79410RK.cpp: In member function 'int MCP79410::deviceWrite(uint8_t, uint8_t, const uint8_t*, size_t)':
/Users/dhhagan/Documents/github/products/MOD-X/fw-mod-x/fw-mod-x/lib/MCP79410RK/src/MCP79410RK.cpp:815:8: error: request for member 'info' in 'log', which is of non-class type 'double(double)'
  815 |    log.info("deviceWrite failed stat=%d", stat);
      |        ^~~~
/Users/dhhagan/Documents/github/products/MOD-X/fw-mod-x/fw-mod-x/lib/MCP79410RK/src/MCP79410RK.cpp: In member function 'int MCP79410::deviceWriteEEPROM(uint8_t, const uint8_t*, size_t)':
/Users/dhhagan/Documents/github/products/MOD-X/fw-mod-x/fw-mod-x/lib/MCP79410RK/src/MCP79410RK.cpp:853:8: error: request for member 'info' in 'log', which is of non-class type 'double(double)'
  853 |    log.info("deviceWriteEEPROM failed stat=%d", stat);
      |        ^~~~
make[4]: *** [../build/target/user/platform-35-m/fw-mod-x/MCP79410RK/src/MCP79410RK.o] Error 1
make[3]: *** [user] Error 2
make[2]: *** [modules/msom/user-part] Error 2
make[1]: *** [make-main] Error 2
make: *** [compile-user] Error 2

 *  The terminal process "/bin/bash '-c', 'make -f '/Users/dhhagan/.particle/toolchains/buildscripts/1.15.0/Makefile' compile-user -s'" terminated with exit code: 2. 
 *  Press any key to close the terminal.

Is the best way to fix this to just rename any conflicting variable names? Or is there something else that needs to change?

Just do a search and replace of log (word, case-sensitive) to _log in that file. It's static so it's not referenced from any other files.

I fixed this issue in a number of libraries, but not that one.

1 Like

Sounds good. I did that to ensure that was the problem - wasn't sure if there was a broader toolchain issue or something, but thanks for quickly clearing that up.

I released new version with the fix as well.

0.0.5 (2024-06-05)

  • Fixed the redeclaration error for log
1 Like