Application fails with ""CMakeCCompilerId.c" failed" and ""CMakeCXXCompilerId.cpp" failed"

Hi,  

I am playing with the nRF5340 Audio Application and trying to read several mics and saving these audio files somewhere. There is an issue open for that hereWith the cues you gave I could read and listen to the read audio in the same board (some help from the Cirrus windows SW), so I created a new application based on some files from the audio app, namely hw_codec.c and .h, cs47l63_comm.c and .h and cs47l63_reg_conf.

The issues I am facing to build this new application are probably related only to my poor knowledge on the sdk, so I opened this new issue to understand these error I have. 

My first couple of errors came from functions within the headers I used, such as:

/Users/joaovitor/Documents/VSCode/Tiresias/microphone_read/src/hw_codec.c:123: undefined reference to `cs47l63_write_reg’
/opt/nordic/ncs/toolchains/580e4ef81c/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: app/libapp.a(hw_codec.c.obj): in function `hw_codec_init':
/Users/joaovitor/Documents/VSCode/Tiresias/microphone_read/src/hw_codec.c:180: undefined reference to `cs47l63_comm_init’
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
 

The workaround was including every c file in the project directory as targets and have all the referenced header directories included in the CMakeLists.txt file:

#
# Copyright (c) 2024 Nordic Semiconductor
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(microphone_read)

target_sources(app PRIVATE 
    src/main.c src/drivers/cs47l63_comm.c 
    ${ZEPHYR_CIRRUS_LOGIC_MODULE_DIR}/cs47l63/cs47l63.c
    ${ZEPHYR_CIRRUS_LOGIC_MODULE_DIR}/common/regmap.c
    ${ZEPHYR_CIRRUS_LOGIC_MODULE_DIR}/cs47l63/generated/cs47l63_syscfg_regs.c
)

# Add the main directory and its subdirectories to the include directories
include_directories(
    /opt/nordic/ncs/v2.6.0-rc2/modules/hal/cirrus-logic
    /opt/nordic/ncs/v2.6.0-rc2/modules/hal/cirrus-logic/common
    /opt/nordic/ncs/v2.6.0-rc2/modules/hal/cirrus-logic/cs47l63
    /opt/nordic/ncs/v2.6.0-rc2/modules/hal/cirrus-logic/cs47l63/config
    /opt/nordic/ncs/v2.6.0-rc2/modules/hal/cirrus-logic/cs47l63/generated
    # Add more directories as needed
)

It does not look as the right way to do it, so this is my first question - what is the best way to show the compiler the referenced header files?

Nevertheless, I could fix the errors, but then I came to another one, for which I couldn't find any solution. I have an error that seems to be unrelated to my application:

Compiling the C compiler identification source file "CMakeCCompilerId.c" failed.
Compiler: /opt/nordic/ncs/toolchains/580e4ef81c/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc 
Build flags: 
Id flags:  

The output was:
1
/opt/nordic/ncs/toolchains/580e4ef81c/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld: /opt/nordic/ncs/toolchains/580e4ef81c/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/lib/libc.a(lib_a-exit.o): in function `exit':
exit.c:(.text.exit+0x34): undefined reference to `_exit'
collect2: error: ld returned 1 exit status


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: /opt/nordic/ncs/toolchains/580e4ef81c/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-g++ 
Build flags: 
Id flags:  

The output was:
1
/opt/nordic/ncs/toolchains/580e4ef81c/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld: /opt/nordic/ncs/toolchains/580e4ef81c/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/lib/libc.a(lib_a-exit.o): in function `exit':
exit.c:(.text.exit+0x34): undefined reference to `_exit'
collect2: error: ld returned 1 exit status


This issue is similar but didn't solve my problem. So my second question is what do I do to solve this problem??

I'll attach my application folder.
Best regards!

SDK version: 2.6.0

Build target: nRF5340 Audio DK

OS: MacOS Sonoma 14.1.2

microphone_read.zip

Parents Reply Children
  • Dejan,

    My build command was a pristine in VSCode Extension. The full log is:

    Building microphone_read
    west build --build-dir /Users/joaovitor/Documents/vscode-study/Tiresias/microphone_read/build /Users/joaovitor/Documents/vscode-study/Tiresias/microphone_read --pristine --board nrf5340_audio_dk_nrf5340_cpuapp --no-sysbuild -- -DNCS_TOOLCHAIN_VERSION=NONE -DBOARD_ROOT=/Users/joaovitor/my_boards -DCACHED_CONF_FILE=/Users/joaovitor/Documents/vscode-study/Tiresias/microphone_read/prj.conf
    
    -- west build: generating a build system
    Loading Zephyr default modules (Zephyr base).
    -- Application: /Users/joaovitor/Documents/vscode-study/Tiresias/microphone_read
    -- CMake version: 3.21.0
    -- Found Python3: /opt/nordic/ncs/toolchains/580e4ef81c/opt/[email protected]/bin/python3.9 (found suitable version "3.9.6", minimum required is "3.8") found components: Interpreter 
    -- Cache files will be written to: /Users/joaovitor/Library/Caches/zephyr
    -- Zephyr version: 3.5.99 (/opt/nordic/ncs/v2.6.0/zephyr)
    -- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
    -- Board: nrf5340_audio_dk_nrf5340_cpuapp
    -- Found host-tools: zephyr 0.16.5 (/opt/nordic/ncs/toolchains/580e4ef81c/opt/zephyr-sdk)
    -- Found toolchain: zephyr 0.16.5 (/opt/nordic/ncs/toolchains/580e4ef81c/opt/zephyr-sdk)
    -- Found Dtc: /opt/nordic/ncs/toolchains/580e4ef81c/bin/dtc (found suitable version "1.6.1", minimum required is "1.4.6") 
    -- Found BOARD.dts: /opt/nordic/ncs/v2.6.0/zephyr/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp.dts
    -- Generated zephyr.dts: /Users/joaovitor/Documents/vscode-study/Tiresias/microphone_read/build/zephyr/zephyr.dts
    -- Generated devicetree_generated.h: /Users/joaovitor/Documents/vscode-study/Tiresias/microphone_read/build/zephyr/include/generated/devicetree_generated.h
    -- Including generated dts.cmake file: /Users/joaovitor/Documents/vscode-study/Tiresias/microphone_read/build/zephyr/dts.cmake
    
    warning: Experimental symbol SAMPLE_RATE_CONVERTER is enabled.
    
    Parsing /opt/nordic/ncs/v2.6.0/zephyr/Kconfig
    Loaded configuration '/opt/nordic/ncs/v2.6.0/zephyr/boards/arm/nrf5340_audio_dk_nrf5340/nrf5340_audio_dk_nrf5340_cpuapp_defconfig'
    Merged configuration '/Users/joaovitor/Documents/vscode-study/Tiresias/microphone_read/prj.conf'
    Configuration saved to '/Users/joaovitor/Documents/vscode-study/Tiresias/microphone_read/build/zephyr/.config'
    Kconfig header saved to '/Users/joaovitor/Documents/vscode-study/Tiresias/microphone_read/build/zephyr/include/generated/autoconf.h'
    -- Found GnuLd: /opt/nordic/ncs/toolchains/580e4ef81c/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd (found version "2.38") 
    -- The C compiler identification is GNU 12.2.0
    -- The CXX compiler identification is GNU 12.2.0
    -- The ASM compiler identification is GNU
    -- Found assembler: /opt/nordic/ncs/toolchains/580e4ef81c/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
    CMake Warning at /opt/nordic/ncs/v2.6.0/zephyr/CMakeLists.txt:126 (message):
      The environment variable 'CPPFLAGS' was set to
      -I/opt/homebrew/opt/llvm/include, but Zephyr ignores flags from the
      environment.  Use 'cmake -DEXTRA_CPPFLAGS=-I/opt/homebrew/opt/llvm/include'
      instead.
    
    
    CMake Warning at /opt/nordic/ncs/v2.6.0/zephyr/CMakeLists.txt:126 (message):
      The environment variable 'LDFLAGS' was set to -L/opt/homebrew/opt/llvm/lib,
      but Zephyr ignores flags from the environment.  Use 'cmake
      -DEXTRA_LDFLAGS=-L/opt/homebrew/opt/llvm/lib' instead.
    
    
    -- Using ccache: /opt/nordic/ncs/toolchains/580e4ef81c/bin/ccache
    CMake Warning at /opt/nordic/ncs/v2.6.0/zephyr/CMakeLists.txt:1957 (message):
      __ASSERT() statements are globally ENABLED
    
    
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /Users/joaovitor/Documents/vscode-study/Tiresias/microphone_read/build
    -- west build: building application
    [1/806] Preparing syscall dependency handling
    
    [10/806] Generating include/generated/version.h
    -- Zephyr version: 3.5.99 (/opt/nordic/ncs/v2.6.0/zephyr), build: d96769faceca
    [801/806] Linking C executable zephyr/zephyr_pre0.elf
    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map /Users/joaovitor/Documents/vscode-study/Tiresias/microphone_read/build/zephyr/zephyr_pre0.map 
    : && ccache /opt/nordic/ncs/toolchains/580e4ef81c/opt/zephyr-sdk/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc  -L/opt/homebrew/opt/llvm/lib   -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr/zephyr_pre0.elf  zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj  -fuse-ld=bfd  -T  zephyr/linker_zephyr_pre0.cmd  -Wl,-Map=/Users/joaovitor/Documents/vscode-study/Tiresias/microphone_read/build/zephyr/zephyr_pre0.map  -Wl,--whole-archive  app/libapp.a  zephyr/libzephyr.a  zephyr/arch/common/libarch__common.a  zephyr/arch/arch/arm/core/libarch__arm__core.a  zephyr/arch/arch/arm/core/cortex_m/libarch__arm__core__cortex_m.a  zephyr/arch/arch/arm/core/cortex_m/cmse/libarch__arm__core__cortex_m__cmse.a  zephyr/arch/arch/arm/core/mpu/libarch__arm__core__mpu.a  zephyr/lib/libc/picolibc/liblib__libc__picolibc.a  zephyr/lib/libc/common/liblib__libc__common.a  zephyr/soc/soc/arm/nordic_nrf/libsoc__arm__nordic_nrf.a  zephyr/subsys/timing/libsubsys__timing.a  zephyr/drivers/clock_control/libdrivers__clock_control.a  zephyr/drivers/console/libdrivers__console.a  zephyr/drivers/gpio/libdrivers__gpio.a  zephyr/drivers/mbox/libdrivers__mbox.a  zephyr/drivers/pinctrl/libdrivers__pinctrl.a  zephyr/drivers/regulator/libdrivers__regulator.a  zephyr/drivers/serial/libdrivers__serial.a  zephyr/drivers/timer/libdrivers__timer.a  modules/nrf/lib/sample_rate_converter/lib..__nrf__lib__sample_rate_converter.a  modules/nrf/drivers/hw_cc3xx/lib..__nrf__drivers__hw_cc3xx.a  modules/cmsis-dsp/libmodules__cmsis-dsp.a  modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a  modules/segger/libmodules__segger.a  -Wl,--no-whole-archive  zephyr/kernel/libkernel.a  -L"/opt/nordic/ncs/toolchains/580e4ef81c/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/thumb/v8-m.main/nofp"  -L/Users/joaovitor/Documents/vscode-study/Tiresias/microphone_read/build/zephyr  -lgcc  zephyr/arch/common/libisr_tables.a  -mcpu=cortex-m33  -mthumb  -mabi=aapcs  -mfp16-format=ieee  -mtp=soft  -Wl,--gc-sections  -Wl,--build-id=none  -Wl,--sort-common=descending  -Wl,--sort-section=alignment  -Wl,-u,_OffsetAbsSyms  -Wl,-u,_ConfigAbsSyms  -nostdlib  -static  -Wl,-X  -Wl,-N  -Wl,--orphan-handling=warn  -Wl,-no-pie  -DPICOLIBC_LONG_LONG_PRINTF_SCANF  /opt/nordic/ncs/v2.6.0/nrfxlib/crypto/nrf_cc312_platform/lib/cortex-m33/soft-float/no-interrupts/libnrf_cc312_platform_0.9.19.a  --specs=picolibc.specs  -lc  -lgcc && cd /Users/joaovitor/Documents/vscode-study/Tiresias/microphone_read/build/zephyr && /opt/nordic/ncs/toolchains/580e4ef81c/Cellar/cmake/3.21.0/bin/cmake -E true
    /opt/nordic/ncs/toolchains/580e4ef81c/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd: app/libapp.a(cs47l63_comm.c.obj):(.rodata.spi+0x0): undefined reference to `__device_dts_ord_151'
    collect2: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: /opt/nordic/ncs/toolchains/580e4ef81c/bin/cmake --build /Users/joaovitor/Documents/vscode-study/Tiresias/microphone_read/build
    
     *  The terminal process terminated with exit code: 1. 
     *  Terminal will be reused by tasks, press any key to close it. 

    Besides the links you sent, I also found this video from Circuit Dojo on which he teaches how Zephyr finds the drives files when interfacing a sensor with the API. Telling it where to look as I am trying here is basically the same thing without the kconfig files.

    Most of my trials were around the make files, changing the command that shows the related files. Except when I simply can't show the compiler the files I need, I have this same error in the log I sent.

  • Hi,

     You could have a look at the troubleshooting steps for devicetree error undefined reference to __device_dts_ord_<N> in the Zephyr documentation.

    EDIT: You can find this answer: "The undefined reference to __device... is a generic problem that happens if you try to get a device pointer from a devicetree node if no such device exists." in this reported Zephyr issue.

    Best regards,
    Dejan

  • Hi, Dejans, 

    Thanks for the reply.

    I'll take my time to study this and also walk through my code again, so I'll close it here and try to get you a more structured question, if needed. 

    Best regards,
    João.

Related