0

I am kinda new to CMake and trying to learn it. Im trying to compile an example project from an IDE with CMake. A problem arises when i try to link some of the vendor supplied static libraries.

The Project is basically:

PROJECT_DIR
  source
    main.c
  include
    main.h
  device
    familyfolder
      morefolders
  emlib
    src
      somesource.c
      em_core.c
      ...
    inc
      someheader.h
      em_core.h
      ...
  protocol
    bluetooth/lib
      EFR32BG1P
        libbluetooth.a
        librail.a
        libnvm3.a
        ...
    bluetooth/ble_stack
      src
        host
          gecko_bglib.c
        soc
          ...
      inc
        soc
          native_gecko.h
          someheader1.h
          someheader2.h
          ...
        host
          someheader3.h
        common
          bg_types.h (which is included by native_gecko.h)
          someheader4.h

CMakeLists.txt within root of project

# Base EFM32 CMake file
#
# This can be used as is as a project base, or by adding the efm32-base
# repository as a submodule to another project, copying this CMakeLists file
# to the top level directory, and updating the BASE_LOCATION variable to reflect this
# change
#
## Copyright (c) 2016 Ryan Kurte
# This file is covered under the MIT license available at: https://opensource.org/licenses/MIT

###### Project Environment #####

# Set minimum CMake version
cmake_minimum_required(VERSION 2.8.4)

# Optional verbose mode, uncomment or pass in -DCMAKE_VERBOSE_MAKEFILE=ON
# set(CMAKE_VERBOSE_MAKEFILE ON)

set(BASE_LOCATION .)

# Set the compiler (must be prior to project setup)
include(${BASE_LOCATION}/toolchain/arm-gcc.cmake)

##### Project Setup #####

# Configure project and languages
project(efm32-test C CXX ASM)

# ${DEVICE} sets the target specific model name
if (NOT DEVICE)
    set(DEVICE EFR32BG1P232F256GM48)
    # set(DEVICE BGM13P22F512GA)
    set(BOARD BRD4100A)
    # set(BLE_LIB EFR32BG13P)
endif ()

# ${JLINK_DEVICE} device model setting specifically for JLink. (Defaults to ${DEVICE} when not set)
# set(JLINK_DEVICE EFM32TG11BXXXF128)

# When ${JLINK_SERVER_IP} is set, JLink will try to connect over IP to a JLink server
# set(JLINK_SERVER_IP 127.0.0.1)

# Set build
if (NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE DEBUG)
endif ()

##### Modules #####

# Libraries can be added to the LIBS variable
# or manually included here.

# Add base libs (emlib, CMSIS, device files)
include(${BASE_LOCATION}/toolchain/efm32-base.cmake)

add_subdirectory(${BASE_LOCATION}/cmsis)
add_subdirectory(${BASE_LOCATION}/emlib)
add_subdirectory(${BASE_LOCATION}/emdrv)
add_subdirectory(${BASE_LOCATION}/device)
add_subdirectory(${BASE_LOCATION}/protocol)
add_subdirectory(${BASE_LOCATION}/hardware)
add_subdirectory(${BASE_LOCATION}/radio)

# This is normally set in efm32-base.cmake, but libraries may modify it so set
# it after libraries/subdirectories have been added
set(CMAKE_EXE_LINKER_FLAGS "${COMMON_DEFINITIONS} -Xlinker -T${LINKER_SCRIPT} -Wl,-Map=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections -Wl,-v")

##### Files #####

# Add project headers
include_directories(${BASE_LOCATION}/include)

# Generate executable and link
add_executable(${PROJECT_NAME}
        source/main.c
        source/init_mcu.c
        source/init_board.c
        source/init_app.c
        source/gatt_db.c
        source/pti.c
        source/app.c
        source/application_properties.c)

efm32_configure_linker_addresses(${PROJECT_NAME})

target_link_libraries(${PROJECT_NAME} ${LIBS} emlib emdrv cmsis device radio)

# Link optional libraries if available
if (${HAS_HARDWARE})
    target_link_libraries(${PROJECT_NAME} hardware)
endif ()

if (${HAS_PROTOCOL})
    target_link_libraries(${PROJECT_NAME} protocol)
endif ()

##### Post build #####

# Add post build commands
include(${BASE_LOCATION}/toolchain/post-build.cmake)

# Add JLink commands
include(${BASE_LOCATION}/toolchain/jlink.cmake)

##### CMake debug prints #####
if (CMAKE_VERBOSE_MAKEFILE)
    print_debug_info()
endif()

CMakeLists.txt within emlib

# EFM32 Emlib CMake file
project(emlib)

# find . -name '*.c' | sort -u
add_library(${PROJECT_NAME}
        src/em_core.c
        src/alot_other_files.c)

target_include_directories(${PROJECT_NAME} PUBLIC inc)

target_link_libraries(${PROJECT_NAME} device protocol)

CMakeList.txt within protocol

project(protocol)

string(TOLOWER ${DEVICE} DEVICE_L)

set(BLE_LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/bluetooth/ble_stack/linker/GCC/${DEVICE_L}.ld")

if (NOT EXISTS ${BLE_LINKER_SCRIPT})
    message("No bluetooth specific linker script defined, skipping protocol")
    set(HAS_PROTOCOL FALSE PARENT_SCOPE)
    return()
endif ()

set(HAS_PROTOCOL TRUE PARENT_SCOPE)

message("Found bluetooth specific linker script, using this instead:\n before: ${LINKER_SCRIPT}\n after: ${BLE_LINKER_SCRIPT}")

set(LINKER_SCRIPT ${BLE_LINKER_SCRIPT} PARENT_SCOPE)

add_library(${PROJECT_NAME}
            bluetooth/ble_stack/src/host/gecko_bglib.c)
#           bluetooth/ble_stack/src/soc/rtos_bluetooth.c)

target_include_directories(${PROJECT_NAME} PUBLIC
        bluetooth/ble_stack/inc/soc
        bluetooth/ble_stack/inc/host
        bluetooth/ble_stack/inc/common)
        
target_link_libraries(${PROJECT_NAME} PUBLIC
  ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth/lib/EFR32BG1P/GCC/libmbedtls.a
  ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth/lib/EFR32BG1P/GCC/libcoex.a
  ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth/lib/EFR32BG1P/GCC/libpsstore.a
  emlib)
  
target_link_libraries(${PROJECT_NAME} PUBLIC
  ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a
  emlib)
  
target_link_libraries(${PROJECT_NAME} PUBLIC
  ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth/lib/EFR32BG1P/GCC/librail.a
  emlib)
  
target_link_libraries(${PROJECT_NAME} PUBLIC
  ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth/lib/EFR32BG1P/GCC/libnvm3.a
  emlib)

Start if main.c - the includes of which native_gecko.h is the main one.

/* Board headers */
#include "init_mcu.h"
#include "init_board.h"
#include "init_app.h"
#include "ble-configuration.h"
#include "board_features.h"

/* Bluetooth stack headers */
#include "bg_types.h"
#include "native_gecko.h"
#include "gatt_db.h"

/* Libraries containing default Gecko configuration values */
#include "em_emu.h"
#include "em_cmu.h"

When i try to include the static libraries and link them to the dependency of emlib

target_link_libraries(protocol PUBLIC
  ${CMAKE_CURRENT_SOURCE_DIR}/bluetooth/lib/EFR32BG1P/GCC/librail.a
  emlib)

in a CMakeLists.txt file in the protocol folder, im getting a

undefined reference to some function

which should be in the libs folder and also is getting compiled beforehand.

As asked, more or less the full error part. which is at the moment mostly a repetition of static library dependency errors.

protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(smp.c.obj): In function `smp_state_master_idle':
smp.c:(.text.smp_state_master_idle+0x298): undefined reference to `mbedtls_mpi_free'
protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(smp.c.obj): In function `smp_init':
smp.c:(.text.smp_init+0x4c): undefined reference to `mbedtls_ecp_group_init'
smp.c:(.text.smp_init+0x54): undefined reference to `mbedtls_ecp_group_load'
protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(sl_malloc.c.obj): In function `sl_malloc':
sl_malloc.c:(.text.sl_malloc+0x4): undefined reference to `CORE_EnterCritical'
sl_malloc.c:(.text.sl_malloc+0x14): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(sl_malloc.c.obj): In function `sl_free':
sl_malloc.c:(.text.sl_free+0x4): undefined reference to `CORE_EnterCritical'
sl_malloc.c:(.text.sl_free+0x16): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(vectors_efr32xg1x.c.obj): In function `vectors_register':
vectors_efr32xg1x.c:(.text.vectors_register+0x6): undefined reference to `CORE_SetNvicRamTableHandler'
protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(vectors_efr32xg1x.c.obj): In function `vectors_init':
vectors_efr32xg1x.c:(.text.vectors_init+0x1c): undefined reference to `CORE_InitNvicVectorTable'
vectors_efr32xg1x.c:(.text.vectors_init+0x24): undefined reference to `CORE_SetNvicRamTableHandler'
vectors_efr32xg1x.c:(.text.vectors_init+0x2c): undefined reference to `CORE_SetNvicRamTableHandler'
vectors_efr32xg1x.c:(.text.vectors_init+0x34): undefined reference to `CORE_SetNvicRamTableHandler'
vectors_efr32xg1x.c:(.text.vectors_init+0x3c): undefined reference to `CORE_SetNvicRamTableHandler'
vectors_efr32xg1x.c:(.text.vectors_init+0x44): undefined reference to `CORE_SetNvicRamTableHandler'
protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(vectors_efr32xg1x.c.obj):vectors_efr32xg1x.c:(.text.vectors_init+0x4c): more undefined references to `CORE_SetNvicRamTableHandler' follow
protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(bg_random_aes.c.obj): In function `aes_ctr_encrypt':
bg_random_aes.c:(.text.aes_ctr_encrypt+0x26): undefined reference to `mbedtls_aes_setkey_enc'
bg_random_aes.c:(.text.aes_ctr_encrypt+0x3a): undefined reference to `mbedtls_aes_crypt_ctr'
protocol/bluetooth/lib/EFR32BG1P/GCC/libbluetooth.a(bg_util_aes.c.obj): In function `bg_init_aes_context':
bg_util_aes.c:(.text.bg_init_aes_context+0x2): undefined reference to `mbedtls_aes_init'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rail_rf.o): In function `RAILINT_e0dfaecc04939a24e643c7a83fed51fa':
rail_rf.c:(.text.RAILInt_SetChannel+0x6): undefined reference to `CORE_EnterCritical'
rail_rf.c:(.text.RAILInt_SetChannel+0x28): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rail_rf_hal.o): In function `RAILINT_2d49aecfcb6d27d54075c2234a55d5e7':
rail_rf_hal.c:(.text.RFHAL_ConfigRxOptions+0x8c): undefined reference to `CORE_EnterCritical'
rail_rf_hal.c:(.text.RFHAL_ConfigRxOptions+0xb0): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rail_rf_hal.o): In function `RAILINT_3212ddcec5ace9cb56e8f1cb3ca8d33c':
rail_rf_hal.c:(.text.RFHAL_SetTimer+0x1a): undefined reference to `CORE_EnterCritical'
rail_rf_hal.c:(.text.RFHAL_SetTimer+0x5a): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rail_rf_hal.o): In function `RAILINT_39475387e0cb29596ec425b4cfae76fb':
rail_rf_hal.c:(.text.RFHAL_GetRxPacketInfo+0x1a): undefined reference to `CORE_EnterCritical'
rail_rf_hal.c:(.text.RFHAL_GetRxPacketInfo+0x30): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rail_calibration.o): In function `RAILINT_3f0b6529856489702e1c986caf70e7aa':
rail_calibration.c:(.text.RAILInt_PendCal+0x6): undefined reference to `CORE_EnterCritical'
rail_calibration.c:(.text.RAILInt_PendCal+0x14): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_bufc.o): In function `RAILINT_8309d0303dd52c35776f1b9d204e124b':
rfhal_bufc.c:(.text.BUFC_SetTxBuffer+0xa): undefined reference to `CORE_EnterCritical'
rfhal_bufc.c:(.text.BUFC_SetTxBuffer+0x26): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_bufc.o): In function `RAILINT_ea701df21b15aeabbf4f1b9be517a6fb':
rfhal_bufc.c:(.text.BUFC_RxBufferReset+0x2): undefined reference to `CORE_EnterCritical'
rfhal_bufc.c:(.text.BUFC_RxBufferReset+0x64): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_bufc.o): In function `RAILINT_e5f98ee4df05ffeec0898fd3dfcac7ef':
rfhal_bufc.c:(.text.BUFC_ReleaseRxPacket+0xa): undefined reference to `CORE_EnterCritical'
rfhal_bufc.c:(.text.BUFC_ReleaseRxPacket+0x2c): undefined reference to `CORE_ExitCritical'
rfhal_bufc.c:(.text.BUFC_ReleaseRxPacket+0xda): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_bufc.o): In function `RAILINT_ee328b192a18bb4569d7a778a9299c02':
rfhal_bufc.c:(.text.BUFC_GetRxPacketInfo+0xa): undefined reference to `CORE_EnterCritical'
rfhal_bufc.c:(.text.BUFC_GetRxPacketInfo+0x4c): undefined reference to `CORE_ExitCritical'
rfhal_bufc.c:(.text.BUFC_GetRxPacketInfo+0xfa): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_protimer.o): In function `RAILINT_fea48c6a0a5dcb75b3cd7e0e0188d110':
rfhal_protimer.c:(.text.PROTIMER_CCTimerStart+0xa): undefined reference to `CORE_EnterCritical'
rfhal_protimer.c:(.text.PROTIMER_CCTimerStart+0x1c): undefined reference to `CORE_ExitCritical'
rfhal_protimer.c:(.text.PROTIMER_CCTimerStart+0x44): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_protimer.o): In function `RAILINT_6d18a45e267fa35e89a132429cb09fd9':
rfhal_protimer.c:(.text.PROTIMER_CheckCcaReallyFailed+0x4): undefined reference to `CORE_EnterAtomic'
rfhal_protimer.c:(.text.PROTIMER_CheckCcaReallyFailed+0xa2): undefined reference to `CORE_ExitAtomic'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_radio.o): In function `RAILINT_49c1638648869baaf18ca93f541e7dd3':
rfhal_radio.c:(.text.RADIO_GetRssi+0xc): undefined reference to `CORE_EnterCritical'
rfhal_radio.c:(.text.RADIO_GetRssi+0x36): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_rtccsync.o): In function `RAILINT_b3ae6c670ad30ab880888943a58faee0':
rfhal_rtccsync.c:(.text.RTCCSYNC_PreSleep+0x12): undefined reference to `CORE_EnterCritical'
rfhal_rtccsync.c:(.text.RTCCSYNC_PreSleep+0xda): undefined reference to `CORE_ExitCritical'
rfhal_rtccsync.c:(.text.RTCCSYNC_PreSleep+0x1cc): undefined reference to `CORE_ExitCritical'
rfhal_rtccsync.c:(.text.RTCCSYNC_PreSleep+0x21a): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_rtccsync.o): In function `RAILINT_b59eec27e1e4352a569b2404f6e35a1b':
rfhal_rtccsync.c:(.text.RTCCSYNC_PostWakeUp+0x24): undefined reference to `CORE_EnterCritical'
rfhal_rtccsync.c:(.text.RTCCSYNC_PostWakeUp+0xe6): undefined reference to `CORE_ExitCritical'
rfhal_rtccsync.c:(.text.RTCCSYNC_PostWakeUp+0x124): undefined reference to `CORE_EnterCritical'
rfhal_rtccsync.c:(.text.RTCCSYNC_PostWakeUp+0x166): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(rfhal_rand.o): In function `RAILINT_06d3d408af442bc7f395514867b33be3':
rfhal_rand.c:(.text.RFRAND_GetRadioEntropy+0x36): undefined reference to `CORE_EnterCritical'
rfhal_rand.c:(.text.RFRAND_GetRadioEntropy+0xa0): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_5f7114cf3ce03d53615d89fe78177694':
generic_phy.c:(.text.GENERIC_PHY_ConfigureRollbackReporting+0x4): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_ConfigureRollbackReporting+0x46): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_933bfa2aa7cb94f384fd9482dc3d4942':
generic_phy.c:(.text.RADIO_RACRxAbort+0x2): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.RADIO_RACRxAbort+0x2c): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_661cd5b832e0dc684eca55cf65a1a4bd':
generic_phy.c:(.text.GENERIC_PHY_DisableRadioIrqs+0x2): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_DisableRadioIrqs+0x90): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_549ae7c6edbff50f2340752aad688b72':
generic_phy.c:(.text.GENERIC_PHY_ConfigureEvents+0x2e): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_ConfigureEvents+0x60): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_ConfigureEvents+0xa2): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_ConfigureEvents+0x2ec): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_ConfigureEvents+0x5c): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_cc007e4287f0aeed09681d7e13e3e8eb':
generic_phy.c:(.text.GENERIC_PHY_PacketTx+0x2): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_PacketTx+0x1c): undefined reference to `CORE_ExitCritical'
generic_phy.c:(.text.GENERIC_PHY_PacketTx+0x30): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_0398a16a4bf50dbcafa68c979c0efcc9':
generic_phy.c:(.text.GENERIC_PHY_SchedulePacketRx+0x14): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_SchedulePacketRx+0x2a): undefined reference to `CORE_ExitCritical'
generic_phy.c:(.text.GENERIC_PHY_SchedulePacketRx+0x5e): undefined reference to `CORE_ExitCritical'
generic_phy.c:(.text.GENERIC_PHY_SchedulePacketRx+0xd0): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_c508b1e616a62d61aefaf693649607f1':
generic_phy.c:(.text.GENERIC_PHY_SchedulePacketTx+0x4): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_SchedulePacketTx+0x1e): undefined reference to `CORE_ExitCritical'
generic_phy.c:(.text.GENERIC_PHY_SchedulePacketTx+0x5a): undefined reference to `CORE_ExitCritical'
generic_phy.c:(.text.GENERIC_PHY_SchedulePacketTx+0x64): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_26621d98bc1a2dc74b7093edea89d850':
generic_phy.c:(.text.GENERIC_PHY_ResetRxFifo+0x4): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_ResetRxFifo+0x1a): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_232b67d119ad2a1a23589ef6ecfa72b8':
generic_phy.c:(.text.GENERIC_PHY_RadioIdle+0x8): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_RadioIdle+0x26): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `FRC_IRQHandler':
generic_phy.c:(.text.FRC_IRQHandler+0x436): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.FRC_IRQHandler+0x466): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/librail.a(generic_phy.o): In function `RAILINT_1446b673acaddfc4b02974cda9fee981':
generic_phy.c:(.text.GENERIC_PHY_SetFeatures+0x6): undefined reference to `CORE_EnterCritical'
generic_phy.c:(.text.GENERIC_PHY_SetFeatures+0x16): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/libnvm3.a(nvm3_lock.c.obj): In function `nvm3_lockBegin':
nvm3_lock.c:(.text.nvm3_lockBegin+0x2): undefined reference to `CORE_EnterCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/libnvm3.a(nvm3_lock.c.obj): In function `nvm3_lockEnd':
nvm3_lock.c:(.text.nvm3_lockEnd+0x4): undefined reference to `CORE_ExitCritical'
protocol/bluetooth/lib/EFR32BG1P/GCC/libnvm3.a(nvm3_hal_flash.c.obj): In function `nvm3_halFlashWriteWords':
nvm3_hal_flash.c:(.text.nvm3_halFlashWriteWords+0xa): undefined reference to `MSC_WriteWord'
protocol/bluetooth/lib/EFR32BG1P/GCC/libnvm3.a(nvm3_hal_flash.c.obj): In function `nvm3_halFlashClose':
nvm3_hal_flash.c:(.text.nvm3_halFlashClose+0x0): undefined reference to `MSC_Deinit'
protocol/bluetooth/lib/EFR32BG1P/GCC/libnvm3.a(nvm3_hal_flash.c.obj): In function `nvm3_halFlashOpen':
nvm3_hal_flash.c:(.text.nvm3_halFlashOpen+0x2): undefined reference to `MSC_Init'
protocol/bluetooth/lib/EFR32BG1P/GCC/libnvm3.a(nvm3_hal_flash.c.obj): In function `nvm3_halFlashPageErase':
nvm3_hal_flash.c:(.text.nvm3_halFlashPageErase+0x4): undefined reference to `MSC_ErasePage'
collect2: error: ld returned 1 exit status
CMakeFiles/efm32-test.dir/build.make:290: recipe for target 'efm32-test' failed
make[2]: *** [efm32-test] Error 1
CMakeFiles/Makefile2:261: recipe for target 'CMakeFiles/efm32-test.dir/all' failed
make[1]: *** [CMakeFiles/efm32-test.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Sibelius
  • 21
  • 6
  • Please, show (add to the question post) the **exact** error message. Citation "undefined reference to somefile.c" has no sense, because "undefined reference" error is about **symbols**, not **files**. – Tsyvarev Aug 04 '20 at 11:15
  • 1
    We would need more information to provide any useful assistance with your problem. Where are these undefined symbols (e.g. `CORE_EnterCritical`) defined? In your CMake snippet, what is `libs`? It would be best to provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) demonstrating the issue, to include a complete CMake file. Also, for ways to link external libraries to your CMake targets (e.g. `protocol`), have a look at the top responses to this [question](https://stackoverflow.com/q/8774593/3987854). – Kevin Aug 04 '20 at 12:23
  • CORE_EnterCritical is defined in source files within the libs subfolder a minimal example is kind of tricky, because i can compile a simple project, but as soon as i add the static libs im running into errors. would a github repo be an appropriate alternative @squareskittles? – Sibelius Aug 04 '20 at 12:26
  • After reducing the project to **only** the minimal required files to produce the issue, it is best to put the content of all relevant files directly in your question post, as text. – Kevin Aug 04 '20 at 12:28
  • "*CORE_EnterCritical is defined in source files within the libs subfolder*"... if the library `librail.a` **depends on** the sources in the `libs` folders, you would want to instead link the target containing these source to the `librail.a` library, not the other way around. However, it's difficult to speculate without seeing a complete example; it's possible you just have a design flaw or cyclic dependency issue... – Kevin Aug 04 '20 at 12:40
  • Added a better description, also a better file structure and more explanation. Its also as minimal as im getting it. @squareskittles – Sibelius Aug 04 '20 at 13:19
  • It appears your top-level executable `efm32-test` is having trouble resolving symbols, which likely indicates you haven't linked all the requisite libraries to it, or they are linked in the wrong order. Things still seem incomplete though... In your top-level CMake file, where is `${LIBS}` defined? – Kevin Aug 04 '20 at 13:48
  • I didnt define ${LIBS}, cause i thought it is enough to link the libraries from the subdirectory? All the CMakeLists are completely posted here, without shortening them. – Sibelius Aug 04 '20 at 14:02

0 Answers0