Build error - undefined reference to _exit
riacob opened this issue · 12 comments
Executing pio run -v -e genericCH32V203C8T6 -t upload
results in the following error:
Processing genericCH32V203C8T6 (board: genericCH32V203C8T6; upload_protocol: wch-link; platform_packages: community-ch32v/tool-wchisp@^0.23.240914; platform: ch32v; framework: ch32v003fun; monitor_speed: 115200)
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CONFIGURATION: https://docs.platformio.org/page/boards/ch32v/genericCH32V203C8T6.html
PLATFORM: WCH CH32V (1.1.0+sha.b7397c2) (git+https://github.com/Community-PIO-CH32V/platform-ch32v.git) > Generic CH32V203C8T6
HARDWARE: CH32V203C8T6 144MHz, 20KB RAM, 64KB Flash
DEBUG: Current (wch-link) On-board (wch-link) External (minichlink)
PACKAGES:
- framework-ch32v003fun @ 0.0.0+sha.31a231f (git+https://github.com/Community-PIO-CH32V/ch32v003fun.git)
- tool-minichlink @ 0.1.0+sha.af02ba5 (git+https://github.com/Community-PIO-CH32V/tool-minichlink.git)
- tool-openocd-riscv-wch @ 2.1100.240729+sha.0986a46 (git+https://github.com/Community-PIO-CH32V/tool-openocd-riscv-wch.git#main)
- tool-wchisp @ 0.23.240914
- tool-wlink @ 0.22.240627+sha.030572c (git+https://github.com/Community-PIO-CH32V/tool-wlink.git#windows)
- toolchain-riscv @ 1.80200.190731+sha.8ee4117 (git+https://github.com/Community-PIO-CH32V/toolchain-riscv-windows.git)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 1 compatible libraries
Scanning dependencies...
Dependency Graph
|-- ch32v003fun (License: Unknown, Path: C:\Users\iacob\Desktop\platform-ch32v-develop\examples\blinky-ch32v003fun\lib\ch32v003fun)
Building in release mode
riscv-none-embed-gcc -o .pio\build\genericCH32V203C8T6\src\blink.o -c -DPLATFORMIO=60116 -DCH32V203C8 -DCH32V20X -DCH32V20x -DCH32V203 -DCH32V20x_D6 -Iinclude -Isrc -Ilib\ch32v003fun src\blink.c
riscv-none-embed-gcc -o .pio\build\genericCH32V203C8T6\lib288\ch32v003fun\ch32v003fun.o -c -DPLATFORMIO=60116 -DCH32V203C8 -DCH32V20X -DCH32V20x -DCH32V203 -DCH32V20x_D6 -Ilib\ch32v003fun lib\ch32v003fun\ch32v003fun.c
riscv-none-embed-gcc-ar rc .pio\build\genericCH32V203C8T6\lib288\libch32v003fun.a .pio\build\genericCH32V203C8T6\lib288\ch32v003fun\ch32v003fun.o
riscv-none-embed-ranlib .pio\build\genericCH32V203C8T6\lib288\libch32v003fun.a
riscv-none-embed-gcc -o .pio\build\genericCH32V203C8T6\firmware.elf .pio\build\genericCH32V203C8T6\src\blink.o -L.pio\build\genericCH32V203C8T6 -Wl,--start-group .pio\build\genericCH32V203C8T6\lib288\libch32v003fun.a -Wl,--end-group
c:/users/iacob/.platformio/packages/toolchain-riscv/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: .pio\build\genericCH32V203C8T6\lib288\libch32v003fun.a(ch32v003fun.o): in function `.L0 ':
ch32v003fun.c:(.text.handle_reset+0x8): undefined reference to `_eusrstack'
c:/users/iacob/.platformio/packages/toolchain-riscv/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: ch32v003fun.c:(.text.handle_reset+0x10): undefined reference to `_sbss'
c:/users/iacob/.platformio/packages/toolchain-riscv/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: ch32v003fun.c:(.text.handle_reset+0x18): undefined reference to `_ebss'
c:/users/iacob/.platformio/packages/toolchain-riscv/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: ch32v003fun.c:(.text.handle_reset+0x2e): undefined reference to `_data_lma'
c:/users/iacob/.platformio/packages/toolchain-riscv/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: ch32v003fun.c:(.text.handle_reset+0x36): undefined reference to `_data_vma'
c:/users/iacob/.platformio/packages/toolchain-riscv/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe: c:/users/iacob/.platformio/packages/toolchain-riscv/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/lib/rv32imac/ilp32\libg.a(lib_a-exit.o): in function `.L0 ':
exit.c:(.text.exit+0x20): undefined reference to `_exit'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\genericCH32V203C8T6\firmware.elf] Error 1
======================================================================================================== [FAILED] Took 1.74 seconds ========================================================================================================
Environment Status Duration
------------------- -------- ------------
ch32v003f4p6_evt_r0 IGNORED
genericCH32V003A4M6 IGNORED
genericCH32V103C6T6 IGNORED
genericCH32V203F6T6 IGNORED
genericCH32V203C8T6 FAILED 00:00:01.738
genericCH32V208CBU6 IGNORED
ch32v307_evt IGNORED
genericCH32V305FBP6 IGNORED
genericCH32V307WCU6 IGNORED
genericCH32X035G8U6 IGNORED
=================================================================================================== 1 failed, 0 succeeded in 00:00:01.738 ===================================================================================================
Pio configuration (not including unused envs):
[env]
platform = ch32v
framework = ch32v003fun
monitor_speed = 115200
[env:genericCH32V203C8T6]
board = genericCH32V203C8T6
upload_protocol = wch-link
platform_packages = community-ch32v/tool-wchisp@^0.23.240914
Windows 10 22H2 19045.5011
Same error from CMD, PowerShell and PowerShell through VSCode.
Tried force-linking the ld script, but that results in the following:
c:/users/iacob/.platformio/packages/toolchain-riscv/bin/../lib/gcc/riscv-none-embed/8.2.0/../../../../riscv-none-embed/bin/ld.exe:C:\Users\iacob\.platformio\packages/framework-ch32v003fun/ch32v003fun/ch32v003fun.ld:5: ignoring invalid character `#' in expression
Deleting the preprocessor directives in the ld script (forcing ram and flash sizes) leads to the error above.
Project tree:
C:.
├───.pio
│ └───build
│ └───genericCH32V203C8T6
│ ├───lib288
│ │ └───ch32v003fun
│ └───src
├───.vscode
├───include
├───lib
│ └───ch32v003fun
├───src
└───test
Something is ultra broken here, it doesn't even generate the ld script (which must be generated by running it through the gcc preprocessor anyways to expand the macros), so a lot of things fail. I'll have a look at it.
Nope. Not able to reproduce that error. The provided ch32v003fun-oled example compiles fine, even for a CH32V203:
[env:genericCH32V203C8T6]
board = genericCH32V203C8T6
Processing genericCH32V203C8T6 (board: genericCH32V203C8T6; platform: ch32v; framework: ch32v003fun; monitor_speed: 115200)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CONFIGURATION: https://docs.platformio.org/page/boards/ch32v/genericCH32V203C8T6.html
PLATFORM: WCH CH32V (1.1.0+sha.18e295e) (git+https://github.com/Community-PIO-CH32V/platform-ch32v.git) > Generic CH32V203C8T6
HARDWARE: CH32V203C8T6 144MHz, 20KB RAM, 64KB Flash
DEBUG: Current (wch-link) On-board (wch-link) External (minichlink)
PACKAGES:
- framework-ch32v003fun @ 0.0.0+sha.31a231f (git+https://github.com/Community-PIO-CH32V/ch32v003fun.git)
- tool-openocd-riscv-wch @ 2.1100.240729 (11.0)
- tool-wlink @ 0.22.240627+sha.030572c (git+https://github.com/Community-PIO-CH32V/tool-wlink.git#windows)
- toolchain-riscv @ 1.80200.190731+sha.8ee4117 (git+https://github.com/Community-PIO-CH32V/toolchain-riscv-windows.git)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
riscv-none-embed-gcc -o .pio\build\genericCH32V203C8T6\FrameworkCh32v003fun\ch32v003fun.o -c -std=gnu11 -Os -g -Wall -msmall-data-limit=8 -msave-restore -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -Wno-comment -march=rv32imacxw -mabi=ilp32 -flto -static-libgcc -nostdlib -DPLATFORMIO=60116 -DCH32V203C8 -DCH32V20X -DCH32V20x -DCH32V203 -DCH32V20x_D6 -D__PIO_BUILD_CH32V003FUN__ -IC:\Users\Max\.platformio\packages\framework-ch32v003fun\ch32v003fun -IC:\Users\Max\.platformio\packages\framework-ch32v003fun\extralibs -Isrc C:\Users\Max\.platformio\packages\framework-ch32v003fun\ch32v003fun\ch32v003fun.c
riscv-none-embed-gcc -o .pio\build\genericCH32V203C8T6\src\i2c_oled.o -c -std=gnu11 -Os -g -Wall -msmall-data-limit=8 -msave-restore -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -fno-common -Wunused -Wuninitialized -Wno-comment -march=rv32imacxw -mabi=ilp32 -flto -static-libgcc -nostdlib -DPLATFORMIO=60116 -DCH32V203C8 -DCH32V20X -DCH32V20x -DCH32V203 -DCH32V20x_D6 -D__PIO_BUILD_CH32V003FUN__ -Iinclude -Isrc -IC:\Users\Max\.platformio\packages\framework-ch32v003fun\ch32v003fun -IC:\Users\Max\.platformio\packages\framework-ch32v003fun\extralibs -Isrc src\i2c_oled.c
riscv-none-embed-gcc -E -P -x c -DTARGET_MCU=CH32V203 -DMCU_PACKAGE=1 -DTARGET_MCU_LD=2 C:\Users\Max\.platformio\packages\framework-ch32v003fun\ch32v003fun\ch32v003fun.ld > C:\Users\Max\temp\ch32v003fun-oled\.pio\build\genericCH32V203C8T6\ldscript.ld
riscv-none-embed-gcc -o .pio\build\genericCH32V203C8T6\firmware.elf -T C:\Users\Max\temp\ch32v003fun-oled\.pio\build\genericCH32V203C8T6\ldscript.ld -Os -march=rv32imacxw -mabi=ilp32 -ffunction-sections -fdata-sections -Wl,-gc-sections --specs=nano.specs --specs=nosys.specs -nostartfiles -Wl,-Map="C:\Users\Max\temp\ch32v003fun-oled\.pio\build\genericCH32V203C8T6\ch32v003fun-oled.map" -flto -static-libgcc -nostdlib .pio\build\genericCH32V203C8T6\FrameworkCh32v003fun\ch32v003fun.o .pio\build\genericCH32V203C8T6\src\i2c_oled.o -L.pio\build\genericCH32V203C8T6 -Wl,--start-group -lm -lgcc
-Wl,--end-group
MethodWrapper(["checkprogsize"], [".pio\build\genericCH32V203C8T6\firmware.elf"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM: [ ] 2.5% (used 512 bytes from 20480 bytes)
Flash: [= ] 10.7% (used 7032 bytes from 65536 bytes)
.pio\build\genericCH32V203C8T6\firmware.elf :
Can you upload a minimal project that reproduces the error?
I totally forgot. I copied the framework/ch32v300fun folder into the "lib" dir of the project, because it wouldn't find the ch32v003fun header. Deleting the ld file does not produce a different result.
I tried to compile the OLED example without making any modification and it returns:
src\i2c_oled.c:11:10: fatal error: ch32v003fun.h: No such file or directory
Copying the folder as i did in the other project, throws:
src\i2c_oled.c:13:10: fatal error: ssd1306_i2c.h: No such file or directory
In fact, I can't find the header myself. Lint also suggests it can't find ssd1306.h
either, nor can I.
EDIT: Trying to copy extralibs folder results in the undefined error..
Here are both projects:
CH32V tests.zip
It just feels like the whole thing is broken, as you said. Maybe I should try to reinstall the platform?
I copied the framework/ch32v300fun folder into the "lib" dir of the project, because it wouldn't find the ch32v003fun header
Nope, with that approach (while also keeping framework = ch32v003fun
or even baremetal), looots of things break, like exactly generating the linker file etc.
I tried to compile the OLED example without making any modification and it returns:
This is the interesting part. I think you have broken local packages. Can you delete:
C:\Users\<user>\.platformio\.cache
C:\Users\<user>\.platformio\packages\framework-ch32v003fun
C:\Users\<user>\.platformio\platforms\ch32v
and retry compilation?
Yeah, I was very sure it could break things, but it was my last attempt.
Problem seems to be down to the PIO level, since:
Executing task: C:\Users\iacob\.platformio\penv\Scripts\platformio.exe run
Processing ch32v003f4p6_evt_r0 (board: ch32v003f4p6_evt_r0; platform: ch32v; framework: ch32v003fun)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Platform Manager: Installing ch32v
UnknownPackageError: Could not find the package with 'ch32v' requirements for your system 'windows_amd64'
* The terminal process "C:\Users\iacob\.platformio\penv\Scripts\platformio.exe 'run'" terminated with exit code: 1.
platformio/platformio-core#3116
Going to try to reinstall the pyenv
Python reinstall didn't change anything, however
platform = https://github.com/Community-PIO-CH32V/platform-ch32v
FINALLY FIXED the issue
I guess that it does not appear to be registered on the PIO platform list, since setting it back to platform = ch32v
now works.
Well, here's the probable reason: https://registry.platformio.org/search?t=platform&q=ch32v
Any plans to integrate it to the registry? Or don't they accept it because it's WIP?
P.S. Very many thanks for the help, you can close this issue now.
Right, so this definitely was broken local packages, and the reinstall fixed it. Nice!
And yes, platform-ch32v is not yet submitted to the PlatformIO registry.. I need to find a proper point in time to make a clean release with everything working to a minimum level. Right now, things are still changing fast, so pulling the git version is best.