Hello,
I am developing an application that requires use of some of the traditional C "stdio.h" functionality. My current development setup is the nRF5340 DK running Zephyr OS v2.7.99. I am attempting to use the dr_libs libraries, particularly dr_wav at the moment, for decoding audio files. These libraries depend on standard C stdio.h, and I am unsure how to properly include this and other standard C headers in my project. I currently have dr_wav.h placed in my app src right next to src/main.c. I'm also unsure the best way to keep external sources separate from my own in the project organization.
So far I have tried adding the include path (from the toolchain) to my project by using "include_directories()" in my CMakeLists.txt:
cmake_minimum_required(VERSION 3.20.0) set(BOARD nrf5340dk_nrf5340_cpuapp) find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(490B_proj) FILE(GLOB app_sources src/*.c src/*.h) include_directories(C:/Users/njyou/ncs/v1.9.0/toolchain/opt/arm-none-eabi/include) target_sources(app PRIVATE ${app_sources})
And VS Code will now recognize that there are two stdio.h available, one from zephyr and one from standard C:
But still, when trying to call dr_wav_init_file() in main.c, I get the following build errors:
c:/users/njyou/ncs/v1.9.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(main.c.obj): in function `drwav__on_seek_stdio': C:\Users\njyou\school\s22\490B\490b_ws\490b_ws\490b_app\src\dr_wav.h:4802: undefined reference to `fseek' c:/users/njyou/ncs/v1.9.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(main.c.obj): in function `fread': C:\Users\njyou\ncs\v1.9.0\toolchain\opt\arm-none-eabi\include\ssp\stdio.h:88: undefined reference to `fread' c:/users/njyou/ncs/v1.9.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(main.c.obj): in function `drwav__on_read': C:\Users\njyou\school\s22\490B\490b_ws\490b_ws\490b_app\src\dr_wav.h:3734: undefined reference to `__assert_func' c:/users/njyou/ncs/v1.9.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(main.c.obj): in function `drwav_fopen': C:\Users\njyou\school\s22\490B\490b_ws\490b_ws\490b_app\src\dr_wav.h:3742: undefined reference to `__errno' c:/users/njyou/ncs/v1.9.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(main.c.obj): in function `drwav__metadata_get_memory': C:\Users\njyou\school\s22\490B\490b_ws\490b_ws\490b_app\src\dr_wav.h:3804: undefined reference to `__assert_func' c:/users/njyou/ncs/v1.9.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(main.c.obj): in function `drwav__metadata_process_info_text_chunk': C:\Users\njyou\school\s22\490B\490b_ws\490b_ws\490b_app\src\dr_wav.h:3826: undefined reference to `__assert_func' c:/users/njyou/ncs/v1.9.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(main.c.obj): in function `drwav__metadata_copy_string': C:\Users\njyou\school\s22\490B\490b_ws\490b_ws\490b_app\src\dr_wav.h:3832: undefined reference to `__assert_func' c:/users/njyou/ncs/v1.9.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(main.c.obj): in function `drwav_buffer_reader_read': C:\Users\njyou\school\s22\490B\490b_ws\490b_ws\490b_app\src\dr_wav.h:3893: undefined reference to `__assert_func' c:/users/njyou/ncs/v1.9.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(main.c.obj): in function `drwav_buffer_reader_read_u16': C:\Users\njyou\school\s22\490B\490b_ws\490b_ws\490b_app\src\dr_wav.h:3936: undefined reference to `__assert_func' c:/users/njyou/ncs/v1.9.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(main.c.obj):C:\Users\njyou\school\s22\490B\490b_ws\490b_ws\490b_app\src\dr_wav.h:3946: more undefined references to `__assert_func' follow c:/users/njyou/ncs/v1.9.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(main.c.obj): in function `drwav_init_file__internal_FILE': C:\Users\njyou\school\s22\490B\490b_ws\490b_ws\490b_app\src\dr_wav.h:4825: undefined reference to `fclose' c:/users/njyou/ncs/v1.9.0/toolchain/opt/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: app/libapp.a(main.c.obj): in function `drwav_fopen': C:\Users\njyou\school\s22\490B\490b_ws\490b_ws\490b_app\src\dr_wav.h:4673: undefined reference to `fopen' collect2.exe: error: ld returned 1 exit status ninja: build stopped: subcommand failed. FATAL ERROR: command exited with status 1: 'c:\Users\njyou\ncs\v1.9.0\toolchain\opt\bin\cmake.EXE' --build 'c:\Users\njyou\school\s22\490B\490b_ws\490b_ws\490b_app\build' The terminal process terminated with exit code: 1.
My question is then, what is the appropriate way to enable use of some of the standard C libraries in my project and remove these dependency issues? Any guidance is greatly appreciated, and please let me know if I can provide any more information to help.