Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By HEck
#82126 Hi Community,

I want to create a ESP_NOW connection. These is my code in my .c file:

Code: Select all#include "espnow.h"
#include "osapi.h"
#include "he_esp_now.h"


uint8_t key[16]= {0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44,
            0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33, 0x44, 0x33};
            
uint8_t OLED1_MAC[6] = {0xCC, 0x50, 0xE3, 0x49, 0xEC, 0x6A};


void ICACHE_FLASH_ATTR
he_initESP_Now (void)
{
   if (esp_now_init()==0)
   {
      os_printf("esp_now init ok\n");
      esp_now_register_recv_cb(ESP_NowRxCB);
      esp_now_set_self_role(ESP_NOW_ROLE_SLAVE);
      if (!esp_now_add_peer(OLED1_MAC, ESP_NOW_ROLE_CONTROLLER, 0, key, 16))
         os_printf("Peer OLED1 added\n");
      else
         os_printf("Add Peer OLED1 failed\n");
   }
   else os_printf("esp_now init failed\n");
   
   if (wifi_softap_dhcps_stop()) os_printf("DHCP stopped\n");
   else os_printf("Could not stop DHCP\n");
}


void ICACHE_FLASH_ATTR
ESP_NowRxCB (uint8_t *macaddr, uint8_t *data, uint8_t len)
{
   int i, ack_count;
   
   uint8_t ack_buf[16];
   uint8_t recv_buf[17];
   os_printf("now from[");
   for (i = 0; i < 6; i++)
      os_printf("%02X, ", macaddr[i]);
   os_printf(" len: %d]:", len);
   os_bzero(recv_buf, 17);
   os_memcpy(recv_buf, data, len<17?len:16);
   if (os_strncmp(data, "ACK", 3) == 0)
   return;
   os_sprintf(ack_buf, "ACK[%08x]", ack_count++);
   esp_now_send(macaddr, ack_buf, os_strlen(ack_buf));
}


This is the corresponding .h file:

Code: Select all#ifndef __HE_ESP_NOW_H__
#define __HE_ESP_NOW_H__


void ICACHE_FLASH_ATTR
he_initESP_Now (void);

void ICACHE_FLASH_ATTR
ESP_NowRxCB (uint8_t *macaddr, uint8_t *data, uint8_t len);

void ICACHE_FLASH_ATTR
ESP_NowTxCB (uint8_t *mac_addr, uint8_t status);


#endif


But when I compiling it with the "ESP8266_NONOS_SDK-3.0", I get this error messages:

esp8266@esp8266-VirtualBox:~/Share/ESP8266_NONOS_SDK-3.0/he_i2c_slave$ make COMPILE=gcc BOOT=none APP=0 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=6
make[1]: Entering directory `/mnt/Share/ESP8266_NONOS_SDK-3.0/he_i2c_slave/user'
make[1]: Leaving directory `/mnt/Share/ESP8266_NONOS_SDK-3.0/he_i2c_slave/user'
xtensa-lx106-elf-gcc -L../lib -nostdlib -T../ld/eagle.app.v6.ld -Wl,--no-check-sections -Wl,--gc-sections -u call_user_start -Wl,-static -Wl,--start-group -lc -lgcc -lhal -lphy -lpp -lnet80211 -llwip -lwpa -lcrypto -lmain -ldriver user/.output/eagle/debug/lib/libuser.a -Wl,--end-group -o .output/eagle/debug/image/eagle.app.v6.out
user/.output/eagle/debug/lib/libuser.a(he_esp_now.o):(.irom0.text+0x14): undefined reference to `esp_now_send'
user/.output/eagle/debug/lib/libuser.a(he_esp_now.o): In function `ESP_NowRxCB':
/mnt/Share/ESP8266_NONOS_SDK-3.0/he_i2c_slave/user/he_esp_now.c:46: undefined reference to `esp_now_send'
/mnt/Share/ESP8266_NONOS_SDK-3.0/he_i2c_slave/user/he_esp_now.c:50: undefined reference to `esp_now_init'
/mnt/Share/ESP8266_NONOS_SDK-3.0/he_i2c_slave/user/he_esp_now.c:50: undefined reference to `esp_now_register_recv_cb'
/mnt/Share/ESP8266_NONOS_SDK-3.0/he_i2c_slave/user/he_esp_now.c:50: undefined reference to `esp_now_set_self_role'
/mnt/Share/ESP8266_NONOS_SDK-3.0/he_i2c_slave/user/he_esp_now.c:50: undefined reference to `esp_now_add_peer'
/mnt/Share/ESP8266_NONOS_SDK-3.0/he_i2c_slave/user/he_esp_now.c:50: undefined reference to `esp_now_init'
/mnt/Share/ESP8266_NONOS_SDK-3.0/he_i2c_slave/user/he_esp_now.c:50: undefined reference to `esp_now_register_recv_cb'
/mnt/Share/ESP8266_NONOS_SDK-3.0/he_i2c_slave/user/he_esp_now.c:50: undefined reference to `esp_now_set_self_role'
user/.output/eagle/debug/lib/libuser.a(he_esp_now.o): In function `he_initESP_Now':
/mnt/Share/ESP8266_NONOS_SDK-3.0/he_i2c_slave/user/he_esp_now.c:15: undefined reference to `esp_now_add_peer'
collect2: error: ld returned 1 exit status
make: *** [.output/eagle/debug/image/eagle.app.v6.out] Error 1
esp8266@esp8266-VirtualBox:~/Share/ESP8266_NONOS_SDK-3.0/he_i2c_slave$





Seems the compiler cannot find the "esp_now"-functions, which are defined in "espnow.h" (comming with the SDK). Furthermore: the compiler pointing to lines 46, 50 in the "he_esp_now.c" file for my function "ESP_NowRxCB" and line 15 for my function "he_initESP_Now", where no of these SDK-functions are called:



What could be wrong?

Thank you for support.
Greetings
Henry
User avatar
By davydnorris
#82155 Open your Makefile and look for lines where you declare what libraries you're using. You're looking for a line that looks like this:

Code: Select all-lc -lgcc -lhal -lphy -lpp -lnet80211 -llwip -lwpa -lcrypto -lmain -ldriver


or maybe a list without the -l at the start, but in the same order:

Code: Select allc gcc hal phy pp net80211 lwip wpa crypto main


When you find that line, add -lespnow (or just espnow) to the end of it