espressif / vscode-esp-idf-extension

Visual Studio Code extension for ESP-IDF projects
Apache License 2.0
1.03k stars 301 forks source link

The same project fails to build on other computers (IDFGH-13774) (VSC-1497) #1322

Open Tinyu-Zhao opened 1 week ago

Tinyu-Zhao commented 1 week ago

Answers checklist.

IDF version.

ESP-IDF v5.4-dev-3201-g46acfdce96

Operating System used.

macOS

How did you build your project?

VS Code IDE

If you are using Windows, please specify command line type.

None

What is the expected behavior?

Compiles normally without errors.

What is the actual behavior?

I encountered an error when trying to build an old IDF project on my new computer(M2 Chip), but it compiled fine on my previous Intel chip macOS.

When I tried to use the VSCode plugin for ESP-IDF, I got an error

I suspected it was a vscode setup issue, so I tried using idf.py build from the command line, and got the same error as when using the VSCode plugin.

/Users/tinyu/Developer/Develop/OneBtn-AppDemo/components/sths34pf80/sths34pf80.c: In function 'sths34pf80_init':
/Users/tinyu/Developer/Develop/OneBtn-AppDemo/components/sths34pf80/sths34pf80.c:105:30: error: assignment to 'stmdev_write_ptr' {aka 'long int (*)(void *, unsigned char,  const unsigned char *, short unsigned int)'} from incompatible pointer type 'esp_err_t (*)(void *, uint8_t,  const uint8_t *, uint16_t)' {aka 'int (*)(void *, unsigned char,  const unsigned char *, short unsigned int)'} [-Wincompatible-pointer-types]
  105 |     me->stmdev_ctx.write_reg = i2c_write;
      |                              ^
/Users/tinyu/Developer/Develop/OneBtn-AppDemo/components/sths34pf80/sths34pf80.c:106:30: error: assignment to 'stmdev_read_ptr' {aka 'long int (*)(void *, unsigned char,  unsigned char *, short unsigned int)'} from incompatible pointer type 'esp_err_t (*)(void *, uint8_t,  uint8_t *, uint16_t)' {aka 'int (*)(void *, unsigned char,  unsigned char *, short unsigned int)'} [-Wincompatible-pointer-types]
  106 |     me->stmdev_ctx.read_reg  = i2c_read;
      |                              ^
/Users/tinyu/Developer/Develop/OneBtn-AppDemo/components/sths34pf80/sths34pf80.c:140:41: error: passing argument 1 of 'sths34pf80_set_odr' from incompatible pointer type [-Wincompatible-pointer-types]
  140 |     int32_t odrErr = sths34pf80_set_odr(&me->stmdev_ctx, STHS34PF80_ODR_AT_1Hz);
      |                                         ^~~~~~~~~~~~~~~
      |                                         |
      |                                         stmdev_ctx_t *

The actual code is


typedef int32_t (*stmdev_write_ptr)(void *, uint8_t, const uint8_t *, uint16_t);
typedef int32_t (*stmdev_read_ptr)(void *, uint8_t, uint8_t *, uint16_t);
typedef void (*stmdev_mdelay_ptr)(uint32_t millisec);

typedef struct
{
  /** Component mandatory fields **/
  stmdev_write_ptr  write_reg;
  stmdev_read_ptr   read_reg;
  /** Component optional fields **/
  stmdev_mdelay_ptr   mdelay;
  /** Customizable optional pointer **/
  void *handle;
} stmdev_ctx_t;

esp_err_t sths34pf80_init(sths34pf80_t *const me, i2c_bus_handle_t i2c_bus_handle, uint8_t dev_addr)
{
    ESP_LOGI(TAG, "Initializing STHS34PF80 instance...");

    /* Add device to I2C bus */

    me->i2c_dev = i2c_bus_device_create(i2c_bus_handle, dev_addr, 400000);
    if (me->i2c_dev == NULL) {
        ESP_LOGE(TAG, "Failed to add device to I2C bus");
    } else {
        ESP_LOGI(TAG, "sths34pf80 create success");
    }

    // i2c_device_config_t i2c_dev_conf = {.scl_speed_hz = 400000, .device_address = dev_addr >> 1};
    // if (i2c_master_bus_add_device(i2c_bus_handle, &i2c_dev_conf, &me->i2c_dev) != ESP_OK) {
    //     ESP_LOGE(TAG, "Failed to add device to I2C bus");
    //     return ret;
    // }

    /* Fill driver interface */
    me->stmdev_ctx.write_reg = i2c_write;
    me->stmdev_ctx.read_reg  = i2c_read;
    me->stmdev_ctx.handle    = me->i2c_dev;
    me->stmdev_ctx.mdelay    = delay_ms;
}

static esp_err_t i2c_read(void *handle, uint8_t reg_addr, uint8_t *reg_data, uint16_t data_len)
{
    i2c_bus_device_handle_t i2c_dev = (i2c_bus_device_handle_t)handle;
    return i2c_bus_read_bytes(i2c_dev, reg_addr, data_len, reg_data);
}

When I hover the mouse over uint8_t, it will prompt me.

image

But when I Go to uint8_t Definition, it will prompt me.

image

I suspect the compiler is pointing to the wrong file: /Library/Developer/CommandLineTools/SDKs/MacOSX15.0.sdk/usr/include/_types/_uint8_t.h

image

Steps to reproduce.

Use vscode esp-idf plugin or idf.py build project

Build or installation Logs.

error_log.txt normal_log.txt

More Information.

No response

brianignacio5 commented 3 days ago

It seems that the error log is using the toolchain /Users/tinyu/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20240906/riscv32-esp-elf/bin/riscv32-esp-elf-gcc while normal log is using /Users/tinyu/.espressif/tools/riscv32-esp-elf/esp-13.2.0_20240530/riscv32-esp-elf/bin/riscv32-esp-elf-gcc

Also Python used is different for both cases: /Users/tinyu/.espressif/python_env/idf5.4_py3.9_env/bin/python for error.log and /Users/tinyu/.espressif/python_env/idf5.4_py3.12_env/bin/python for normal log.

I would suggest review that both ESP-IDF setup to match version (with doctor command for example) with the intended ESP-IDF version from your application code.

Tinyu-Zhao commented 3 days ago

It seems that the error log is using the toolchain /Users/tinyu/.espressif/tools/riscv32-esp-elf/esp-14.2.0_20240906/riscv32-esp-elf/bin/riscv32-esp-elf-gcc while normal log is using /Users/tinyu/.espressif/tools/riscv32-esp-elf/esp-13.2.0_20240530/riscv32-esp-elf/bin/riscv32-esp-elf-gcc

Also Python used is different for both cases: /Users/tinyu/.espressif/python_env/idf5.4_py3.9_env/bin/python for error.log and /Users/tinyu/.espressif/python_env/idf5.4_py3.12_env/bin/python for normal log.

I would suggest review that both ESP-IDF setup to match version (with doctor command for example) with the intended ESP-IDF version from your application code.

Thank you for your reply, I will try again.