Cmake function not linked correctly. Function return 0

I’m new to Cmake, and am a bit beaten by it.

In my main project I’m trying to fetchcontent a git Repo and add it to my main project as a lib.
The problem I have is that everything builds fine. however when I call the function int GetVersion(){return 2;} from the LIB, it simply returns 0.

I build a .elf for an STM32 Microcontroller using STM32CUBEIDE.
I already made a project without IDE and made .exe and… it works as expected it prints 3…

There are no errors or warning other that a = unused. But the optimizer is turned of and i can step through the code.
Since everything builds fine, I have a feeling it is not linking well.
Am I missing anything, what can I do to debug this further?

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>//Main.c
#include <stdint.h>
#include "ringbuff.h"
int main(void)
{
static int a = 1;
a = GetVersion(); // after this call a = 0
for(;;);
}
</code>
<code>//Main.c #include <stdint.h> #include "ringbuff.h" int main(void) { static int a = 1; a = GetVersion(); // after this call a = 0 for(;;); } </code>
//Main.c
#include <stdint.h>
#include "ringbuff.h"

int main(void)
{
    static int a = 1;
    a = GetVersion(); // after this call a = 0
    for(;;);
}
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>//ringbuff.c from the lib. The header contains: 'int GetVersion2();'
#include "ringbuff.h"
int GetVersion()
{
return 3;
}
</code>
<code>//ringbuff.c from the lib. The header contains: 'int GetVersion2();' #include "ringbuff.h" int GetVersion() { return 3; } </code>
//ringbuff.c from the lib.  The header contains: 'int GetVersion2();'
#include "ringbuff.h"

int GetVersion()
{
    return 3;
}

cMakelists of Main project. Everything is standard cmaketemplate from the IDE, I’ve added the part inbetween the Import Lib comments

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>cmake_minimum_required(VERSION 3.20)
set (PROJECT_NAME "CM7")
# LIST SOURCE FILES HERE
set (PROJECT_SOURCES
Startup/startup_stm32h755zitx.s
Sources/system_stm32h7xx_dualcore_boot_cm4_cm7.c
Sources/main.c
Sources/syscalls.c
Sources/sysmem.c
)
# LIST COMPILER DEFINITIONS HERE
set (PROJECT_DEFINES
CORE_CM7
STM32H755xx
)
# LIST INCLUDE DIRECTORIES HERE
set (PROJECT_INCLUDES
Sources
#STM32 HAL & CMSIS
Drivers/STM32H7xx_HAL_Driver/Inc
Drivers/STM32H7xx_HAL_Driver/Inc/Legacy
Drivers/CMSIS/Device/ST/STM32H7xx/Include
Drivers/CMSIS/Include
)
project(${PROJECT_NAME})
enable_language(ASM)
add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${CMAKE_PROJECT_NAME}>)
################# Import module #####################
include(FetchContent)
Set(FETCHCONTENT_QUIET FALSE)
FetchContent_Declare(
ringbuff
GIT_REPOSITORY https://github.com/TESTMODULE.git
GIT_TAG V0.7
GIT_PROGRESS TRUE
)
FetchContent_MakeAvailable(ringbuff)
target_include_directories(${PROJECT_NAME}
PUBLIC ${ringbuff_SOURCE_DIR}
)
target_link_libraries(${PROJECT_NAME}
PRIVATE ringbuff
)
#####################################################
target_compile_definitions(${PROJECT_NAME}
PRIVATE ${PROJECT_DEFINES}
)
target_include_directories(${PROJECT_NAME}
PUBLIC ${PROJECT_INCLUDES}
)
set (CMAKE_EXECUTABLE_SUFFIX ".elf")
set (CMAKE_STATIC_LIBRARY_SUFFIX ".a")
set (CMAKE_C_FLAGS "-mcpu=Cortex-M7 -O0 -std=gnu11 -mfpu=fpv5-d16 --specs=nano.specs -mthumb -Wall")
set (CMAKE_EXE_LINKER_FLAGS "-T../STM32H755ZITX_FLASH.ld --specs=nosys.specs -Wl,-Map=test.map -Wl,--gc-sections -static -Wl,--start-group -lc -lm -Wl,--end-group")
set (CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp")
</code>
<code>cmake_minimum_required(VERSION 3.20) set (PROJECT_NAME "CM7") # LIST SOURCE FILES HERE set (PROJECT_SOURCES Startup/startup_stm32h755zitx.s Sources/system_stm32h7xx_dualcore_boot_cm4_cm7.c Sources/main.c Sources/syscalls.c Sources/sysmem.c ) # LIST COMPILER DEFINITIONS HERE set (PROJECT_DEFINES CORE_CM7 STM32H755xx ) # LIST INCLUDE DIRECTORIES HERE set (PROJECT_INCLUDES Sources #STM32 HAL & CMSIS Drivers/STM32H7xx_HAL_Driver/Inc Drivers/STM32H7xx_HAL_Driver/Inc/Legacy Drivers/CMSIS/Device/ST/STM32H7xx/Include Drivers/CMSIS/Include ) project(${PROJECT_NAME}) enable_language(ASM) add_executable(${PROJECT_NAME} ${PROJECT_SOURCES}) add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${CMAKE_PROJECT_NAME}>) ################# Import module ##################### include(FetchContent) Set(FETCHCONTENT_QUIET FALSE) FetchContent_Declare( ringbuff GIT_REPOSITORY https://github.com/TESTMODULE.git GIT_TAG V0.7 GIT_PROGRESS TRUE ) FetchContent_MakeAvailable(ringbuff) target_include_directories(${PROJECT_NAME} PUBLIC ${ringbuff_SOURCE_DIR} ) target_link_libraries(${PROJECT_NAME} PRIVATE ringbuff ) ##################################################### target_compile_definitions(${PROJECT_NAME} PRIVATE ${PROJECT_DEFINES} ) target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_INCLUDES} ) set (CMAKE_EXECUTABLE_SUFFIX ".elf") set (CMAKE_STATIC_LIBRARY_SUFFIX ".a") set (CMAKE_C_FLAGS "-mcpu=Cortex-M7 -O0 -std=gnu11 -mfpu=fpv5-d16 --specs=nano.specs -mthumb -Wall") set (CMAKE_EXE_LINKER_FLAGS "-T../STM32H755ZITX_FLASH.ld --specs=nosys.specs -Wl,-Map=test.map -Wl,--gc-sections -static -Wl,--start-group -lc -lm -Wl,--end-group") set (CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp") </code>
cmake_minimum_required(VERSION 3.20)

set (PROJECT_NAME             "CM7")

# LIST SOURCE FILES HERE
set (PROJECT_SOURCES
    Startup/startup_stm32h755zitx.s
    Sources/system_stm32h7xx_dualcore_boot_cm4_cm7.c
    Sources/main.c
    Sources/syscalls.c
    Sources/sysmem.c
    )

# LIST COMPILER DEFINITIONS HERE
set (PROJECT_DEFINES
        CORE_CM7
        STM32H755xx
    ) 

# LIST INCLUDE DIRECTORIES HERE
set (PROJECT_INCLUDES
    Sources
      
    #STM32 HAL & CMSIS
    Drivers/STM32H7xx_HAL_Driver/Inc
    Drivers/STM32H7xx_HAL_Driver/Inc/Legacy
    Drivers/CMSIS/Device/ST/STM32H7xx/Include
    Drivers/CMSIS/Include
    )

project(${PROJECT_NAME})
enable_language(ASM)

add_executable(${PROJECT_NAME} ${PROJECT_SOURCES})
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${CMAKE_PROJECT_NAME}>)

################# Import module #####################
include(FetchContent)
Set(FETCHCONTENT_QUIET FALSE)
FetchContent_Declare(
  ringbuff
  GIT_REPOSITORY https://github.com/TESTMODULE.git
  GIT_TAG        V0.7
  GIT_PROGRESS   TRUE
)
FetchContent_MakeAvailable(ringbuff)

target_include_directories(${PROJECT_NAME}
    PUBLIC ${ringbuff_SOURCE_DIR}
)

target_link_libraries(${PROJECT_NAME} 
    PRIVATE ringbuff
)
#####################################################

target_compile_definitions(${PROJECT_NAME}
    PRIVATE ${PROJECT_DEFINES}
)
target_include_directories(${PROJECT_NAME}
    PUBLIC ${PROJECT_INCLUDES}
)

set (CMAKE_EXECUTABLE_SUFFIX ".elf")
set (CMAKE_STATIC_LIBRARY_SUFFIX ".a")
set (CMAKE_C_FLAGS "-mcpu=Cortex-M7 -O0 -std=gnu11 -mfpu=fpv5-d16 --specs=nano.specs -mthumb -Wall")
set (CMAKE_EXE_LINKER_FLAGS "-T../STM32H755ZITX_FLASH.ld --specs=nosys.specs -Wl,-Map=test.map -Wl,--gc-sections -static -Wl,--start-group -lc -lm -Wl,--end-group")
set (CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp")

Cmakelist of the ringbuff lib

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># Minimum version of CMake required
cmake_minimum_required(VERSION 3.20)
# Project name
project(RingBuffer C)
# Add the source files
add_library(ringbuff STATIC ringbuff.c)
</code>
<code># Minimum version of CMake required cmake_minimum_required(VERSION 3.20) # Project name project(RingBuffer C) # Add the source files add_library(ringbuff STATIC ringbuff.c) </code>
# Minimum version of CMake required
cmake_minimum_required(VERSION 3.20)

# Project name
project(RingBuffer C)

# Add the source files
add_library(ringbuff STATIC ringbuff.c)

7

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật