Hi all, I’m trying to include the example from here u8g2-hal-esp-idf/test_SSD1306_i2c.c at master · mkfrey/u8g2-hal-esp-idf · GitHub in my application to test the function of a display. The linker doesn’t complain about including u8g2.h
, but it does complain about undefined references to symbols that are included in u8g2.h
, which I don’t understand.
I’ve added the following build flag, which as I mentioned allows the import of u8g2.h
without complaints.
-I/<system_path>/PlatformIO/Projects/<project_name>/.pio/libdeps/stable/U8g2/src/clib -DESP_IDF
My main.c looks like this:
#include <driver/gpio.h>
#include <driver/spi_master.h>
#include <esp_log.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <stdio.h>
#include <string.h>
#include "u8g2.h"
#include "u8g2_esp32_hal.h"
#include "sdkconfig.h"
#define OLED_I2C_ADDRESS 0x3C
#define PIN_SDA 5
#define PIN_SCL 2
static const char* TAG = "ssd1306";
void app_main(void)
{
// esp_log_set_vprintf(esp_apptrace_vprintf);
ESP_LOGI(TAG, "Initializing...");
u8g2_esp32_hal_t u8g2_esp32_hal = U8G2_ESP32_HAL_DEFAULT;
u8g2_esp32_hal.sda = PIN_SDA;
u8g2_esp32_hal.scl = PIN_SCL;
u8g2_esp32_hal_init(u8g2_esp32_hal);
u8g2_t u8g2; // a structure which will contain all the data for one display
u8g2_Setup_ssd1306_i2c_128x32_univision_f(
&u8g2, U8G2_R0,
// u8x8_byte_sw_i2c,
u8g2_esp32_i2c_byte_cb,
u8g2_esp32_gpio_and_delay_cb); // init u8g2 structure
u8x8_SetI2CAddress(&u8g2.u8x8, OLED_I2C_ADDRESS);
ESP_LOGI(TAG, "u8g2_InitDisplay");
u8g2_InitDisplay(&u8g2); // send init sequence to the display, display is in
// sleep mode after this,
ESP_LOGI(TAG, "u8g2_SetPowerSave");
u8g2_SetPowerSave(&u8g2, 0); // wake up display
ESP_LOGI(TAG, "u8g2_ClearBuffer");
u8g2_ClearBuffer(&u8g2);
ESP_LOGI(TAG, "u8g2_DrawBox");
u8g2_DrawBox(&u8g2, 0, 26, 80, 6);
u8g2_DrawFrame(&u8g2, 0, 26, 100, 6);
ESP_LOGI(TAG, "u8g2_SetFont");
u8g2_SetFont(&u8g2, u8g2_font_ncenB14_tr);
ESP_LOGI(TAG, "u8g2_DrawStr");
u8g2_DrawStr(&u8g2, 2, 17, "Hi nkolban!");
ESP_LOGI(TAG, "u8g2_SendBuffer");
u8g2_SendBuffer(&u8g2);
ESP_LOGI(TAG, "All done!");
vTaskDelete(NULL);
}
When I compile, I see a ton of errors along the lines of main.c:67: undefined reference to 'u8g2_SendBuffer'
. But if I look in u8g2.h
, I clearly see those symbols defined. It appears as thought the linker can’t find any of the symbols defined in that header, despite successfully importing the header.
Here’s my full platformio.ini (I’m using a branch of esp-idf for some 4.0 features, which I don’t believe is related to this problem):
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:stable]
platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.3rc1/platform-espressif32-2.0.3.zip
board = esp32dev
framework = espidf
monitor_speed = 115200
lib_deps =
https://github.com/mkfrey/u8g2-hal-esp-idf.git
olikraus/U8g2@2.33.9
build_flags =
-I/<system_path>/PlatformIO/Projects/<project_name>/.pio/libdeps/stable/U8g2/src/clib -DESP_IDF