Skip to content

Compile/Linker options required for using static library and FetchContent #100

@jhird-fraser

Description

@jhird-fraser

This might be my build system being badly setup but it is crucial to specify the link options for nanoMODBUS when importing it into the project using CMake's FetchContent functionality.

The current readme states

FetchContent_Declare(
        nanomodbus
        GIT_REPOSITORY https://github.com/debevv/nanoMODBUS
        GIT_TAG master # or the version you want
        GIT_SHALLOW TRUE
)

FetchContent_MakeAvailable(nanomodbus)

#...

add_executable(your_program source_codes)
target_link_libraries(your_program nanomodbus)

Where in reality the following is needed (adapted from my project using atsamd21J18A) so that your program doesn't crash when deployed to the target. Without it you can build the library but any calls to it will result in runtime errors.

FetchContent_Declare(
        nanomodbus
        GIT_REPOSITORY https://github.com/debevv/nanoMODBUS
        GIT_TAG master # or the version you want
        GIT_SHALLOW TRUE
)

FetchContent_MakeAvailable(nanomodbus)

target_compile_options(nanomodbus PRIVATE
		${CPU_PARAMETERS}  # -mcpu=cortex-m0plus
	)

target_link_options(nanomodbus PRIVATE
	-T${MCU_LINKER_SCRIPT} #linker script for atsamd21J18A
	-L${MCU_LINKER_LIBRARY_PATH} #linker lib for atsamd21J18A
	${CPU_PARAMETERS} # -mcpu=cortex-m0plus
       #etc.     
)

target_link_libraries(${APP_EXEC} nanomodbus)

Might be obvious for those more familiar with CMake but thought I'd make the issue to highlight it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions