Ld emits ignoring invalid character `#' in expression

What can cause this error?
c:/users/frank/.platformio/packages/toolchain-xtensa32/bin/…/lib/gcc/xtensa-esp32-elf/5.2.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe:esp32_out.ld:23: ignoring invalid character `#’ in expression
c:/users/frank/.platformio/packages/toolchain-xtensa32/bin/…/lib/gcc/xtensa-esp32-elf/5.2.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe:esp32_out.ld:23: syntax error

Compile part is clean. Message gives no hint as to where to look. or what might be wrong. I have 1 global,

i2c_port_t i2c_num; defined in the main module and used in a submodule. I have included

extern i2c_port_t i2c_num;

in its header (.h) file
This may be a red herring but I have tried a number of other possibilities. that don’t go anywhere

Any help is appreciated.

Could you take a look at the esp32_out.ld-file in your projects directory? It can be found in your projects directory in the .pioenvs-folder. Just use the windows search function to get the exact path there. Open the file in any texteditor and paste the region around line 23 here.

I encountered the same error… but am not sure what caused it. Nothing special in the code - I was only compiling the included ESP_IDF blink example, and added #define CONFIG_BLINK_GPIO 1 to the top to let it compile.

For some reason… that commented out define snuck in at line 23 - removal of which also made the build complete successfully. I have no idea how that happened - I have been playing around with both the stable and beta versions of platformio, and did edit the default sdkconfig.h it pulls in (to identify which file it was using, and by adding some text to the top header block). I’m not sure if reverting that change made any difference, as I now can’t reproduce this error.

Hopefully this will help anyone else who encounters it - do check the .pioenvs (soon to be .pio\build) and check the line of the esp32_out.ld mentioned in the error - if it’s a commented out define, you can safely remove it and try the build again.

20:  * Espressif IoT Development Framework Configuration
21: *
22:  */
23: //#define CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC 1
24: /* If BT is not built at all */
25: MEMORY
26:{
1 Like

can you help me? please


i can´t find esp32_out.ld

Close, but not quite… scroll further down… files are listed after folders :wink:

1 Like

Thank you so much pfeerick i found it.

1 Like

I have experienced that error too some time ago. Seems like whatever is parsing the sdkconfig.h doesn’t like single line comments (//) and only knows how to handle multiline comments (/**/). That is why you get an error if there are single line comments in your sdkconfig.h.

1 Like

Yeah… something is happening that results in an edit to the linker script which adds the commented define causing ld having in a hissy fit as // isn’t part of the linker script format specification…

Something is obviously go wrong here… not sure what though…

1 Like

Yes, /**/ will work. But you have to delete the esp32_out.ld file so it will be regenerated.