0

I'm trying to run the AzureIoTProtocol_MQTT/esp8266 example, but I get linker errors:

Archiving built core (caching) in: /var/folders/fj/y3vtrz597kv4885q1b_5qypr0000gn/T/arduino_cache_934614/core/core_esp8266_esp8266_d1_mini_CpuFrequency_80,UploadSpeed_921600,FlashSize_4M3M_e1e103f2055a19e071ac9522162e1787.a libraries/AzureIoTHub/sdk/agenttypesystem.c.o: In function sscanfd': /Users/jonas/Documents/Arduino/libraries/AzureIoTHub/src/sdk/agenttypesystem.c:2826: undefined reference tostrtoull' libraries/AzureIoTHub/sdk/agenttypesystem.c.o: In function sscanfllu': /Users/jonas/Documents/Arduino/libraries/AzureIoTHub/src/sdk/agenttypesystem.c:2826: undefined reference tostrtoull' libraries/AzureIoTHub/sdk/agenttypesystem.c.o:(.text.CreateAgentDataType_From_String+0xac): undefined reference to strtof' libraries/AzureIoTHub/sdk/agenttypesystem.c.o: In function CreateAgentDataType_From_String': /Users/jonas/Documents/Arduino/libraries/AzureIoTHub/src/sdk/agenttypesystem.c:3571: undefined reference to `strtof' collect2: error: ld returned 1 exit status

The issue can be broken down to the call to strtof function call. I get the same error with only this very simple code snippet:

#include <stdlib.h>

void setup() {
  char szOrbits[] = "686.97";
  float f;
  f = strtof (szOrbits, NULL);
}

void loop() {
}

Tested environment: Mac OS X 10.13.2 with Arduino 1.8.3 AND Windows 10 with Arduino 1.8.5.

1

Its because the "strtof" function resides in "stdlib.h", "Stdio.h" deals with i/o tasks.

Since you din't include you get that undefined reference error. Correct that and compile again. Hopefully the error shall be resolved, else reply in the comments.

Update1:

After digging around standard gcc stdlib definitions and avr-gcc definitions found out that the above solution works for a gcc and not avr-gcc especially the 8-bit ones which the arduino IDE compiles for uno and the works as expected for 32bit processors like of Due.

Cite:

  1. https://www.arduino.cc/reference/en/language/variables/data-types/double/
  2. https://www.arduino.cc/reference/en/language/variables/data-types/float/

Reason:

The size of the double and float is the same, ie: 4 bytes and even if you use double its actually the float itself and wont gain any precision advantage.

Solution:

Since the size of the double and the float is same there is not point in having two function definition doing the same job. so

  1. Use "strtod" instead of "strtof" or
  2. Define a macro #define strtof(A, B) strtod(A, B) in the begning of your sketch so that the "strtod" handles the functioning of the "strtof".
  • 1
    changed to stdlib.h and same error. – appsthatmatter Jan 13 '18 at 10:13
  • @appsthatmatter i have updated my answer for your error. do check. – 25mhz Jan 13 '18 at 16:00
  • 1
    thanks for the answer. Since the function is used in a third party library I can not change it easily to float. But anyway, I managed it to run with this steps (replicable on Mac and Windows): 1) clean install of Arduino IDE, 2) install ESP8266 via git (see the README), 3) verify the program once for Board NodeMCU 1.0 (ESP 12-E). – appsthatmatter Jan 14 '18 at 18:54
0

Its because you haven't added the core of esp8266 to the arduino IDE. you are defaulting it to the "UNO" board and compiling it. so you get that error for which i have explanation

here: https://arduino.stackexchange.com/a/48719/3557

solution for your problem is simple added the esp8266 core and select the right board and compile again.

Cite: https://learn.sparkfun.com/tutorials/esp8266-thing-hookup-guide/installing-the-esp8266-arduino-addon

Follow above link and install the esp8266 core.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.