How to link a library

My demo application depends on mbed-client. In addition I need to link a proprietary library, foo.a.

CMakeLists.txt in demo/source contains the following two lines:

#demo.c implements my mbed-client demo, which also requires foo.a
add_executable (demo demo.c)
#Link foo.a (in addition to all the other libraries mbed-client depends on such as HAL/CMSIS)
target_link_libraries (demo foo.a)

The linker reported error: Cannot find entry symbol Reset_Handler. I know my demo runs on the K64 target if I don’t include foo.a.

Question: What is the proper way to include a proprietary library?

Thanks!

Planning to add some more docs on using CMake to link custom things soon – for now, assuming you have this structure:

source/
    demo.c
    foo.a

You’ll need to add source/CMakeLists.txt like this:

add_executable(demo demo.c)
target_link_libraries(demo
    foo.a # if this can't be found, use ${CMAKE_CURRENT_SOURCE_DIR}/foo.a
    mbed-client # this is what you're missing – when you override the CMake that
                # yotta generates you need to still make sure to link against all
                # your dependencies, as you've replaced the generated CMakeList.txt
                # that used to do that.
)

An alternative to this is, instead of writing a custom CMakeLists.txt file to describe how to compile your sources, just add an .cmake file in the source directory. The yotta-generated CMakeLists will include any .cmake files found in the same directory, so you can use this to add an additional link dependency without having to redefine anything.

for example, source/link_foo.cmake might just contain the line:

target_link_libraries(demo foo.a) #the "demo" name here will be the same as your module's name

James, thanks for the tip! Now I am able to link my application. However looks like the build process no longer automatically convert elf to bin format. Any tricks I should play in CMakeLists.txt to do the conversion?

The frdm-k64f targets that we currently support for mbed OS should do this conversion automatically. If you inherit from the mbed-gcc/-armcc targets, this functionality will be automatically inherited. If you need to customise/override it, you can copy what the base mbed targets do into your own description: