wagiminator / CH32V003-GameConsole

Handheld RISC-V Mini Game Console with OLED Display
https://oshwlab.com/wagiminator/ch32v003j4m6-game-console
Other
248 stars 28 forks source link

Build on macOS & Ubuntu - undefined reference to 'memcpy' and 'memset' #1

Closed limingjie closed 1 year ago

limingjie commented 1 year ago

Thank you for the great project!

I ran into the undefined reference to 'memcpy' and 'memset' while making the project, after Googling, I found a solution.

Solution

Append -fno-builtin to CFLAGS to resolve the problem

How to replicate the issue and solve it

Ubuntu (Multipass)

$ uname -a
Linux ch32v003 5.15.0-76-generic #83-Ubuntu SMP Thu Jun 15 19:16:32 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
$ sudo apt install build-essential libnewlib-dev gcc-riscv64-unknown-elf
$ git clone https://github.com/wagiminator/CH32V003-GameConsole.git
$ cd CH32V003-GameConsole/software/tiny_invaders/
$ make all
Building tiny_invaders.elf ...
/usr/lib/riscv64-unknown-elf/bin/ld: /tmp/tiny_invaders.elf.wm9Spl.ltrans0.ltrans.o: in function '.L325':
/home/ubuntu/CH32V003-GameConsole/software/tiny_invaders/tiny_invaders.c:624: undefined reference to 'memcpy'
/usr/lib/riscv64-unknown-elf/bin/ld: /tmp/tiny_invaders.elf.wm9Spl.ltrans0.ltrans.o: in function '.L0 ':
/home/ubuntu/CH32V003-GameConsole/software/tiny_invaders/tiny_invaders.c:168: undefined reference to 'memset'
collect2: error: ld returned 1 exit status
make: *** [makefile:46: tiny_invaders.elf] Error 1

# Append `-fno-builtin` to `CFLAGS` to resolve the problem 
$ make all
Building tiny_invaders.elf ...
Building tiny_invaders.lst ...
Building tiny_invaders.map ...
Building tiny_invaders.bin ...
Building tiny_invaders.hex ...
Disassembling to tiny_invaders.asm ...
------------------
FLASH: 7324 bytes
SRAM:  20 bytes
------------------

macOS

$ uname -a
Darwin Mingjie-MBP 22.5.0 Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:22 PDT 2023; root:xnu-8796.121.3~7/RELEASE_X86_64 x86_64
$ brew tap riscv-software-src/riscv
$ brew install riscv-tools
$ git clone https://github.com/wagiminator/CH32V003-GameConsole.git
$ cd CH32V003-GameConsole/software/tiny_invaders/
$ make all
Building tiny_invaders.elf ...
/usr/local/Cellar/riscv-gnu-toolchain/main/lib/gcc/riscv64-unknown-elf/12.2.0/../../../../riscv64-unknown-elf/bin/ld: /var/folders/5v/vm6gxf4d2z97cg_m6r2749_80000gn/T//ccvrcsE7.ltrans0.ltrans.o: in function `.L323':
/Users/mingjie/Documents/CH32V003/CH32V003-GameConsole/software/tiny_invaders/tiny_invaders.c:168: undefined reference to `memcpy'
/usr/local/Cellar/riscv-gnu-toolchain/main/lib/gcc/riscv64-unknown-elf/12.2.0/../../../../riscv64-unknown-elf/bin/ld: /var/folders/5v/vm6gxf4d2z97cg_m6r2749_80000gn/T//ccvrcsE7.ltrans0.ltrans.o:/Users/mingjie/Documents/CH32V003/CH32V003-GameConsole/software/tiny_invaders/tiny_invaders.c:171: undefined reference to `memset'
collect2: error: ld returned 1 exit status
make: *** [tiny_invaders.elf] Error 1

# Append `-fno-builtin` to `CFLAGS` to resolve the problem 
$ make all
Building tiny_invaders.elf ...
Building tiny_invaders.lst ...
Building tiny_invaders.map ...
Building tiny_invaders.bin ...
Building tiny_invaders.hex ...
Disassembling to tiny_invaders.asm ...
------------------
FLASH: 7328 bytes
SRAM:  20 bytes
------------------
wagiminator commented 1 year ago

Hi and thanks for the tip. This is probably due to a different compiler version. Since it works for me both with and without this compiler flag, I add it by default.

limingjie commented 1 year ago

Thank you!