Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a library dependency in an Azure Sphere Visual Studio Project?

I am building an Azure Sphere C application, starting from the HTTPS_Curl_Easy sample project. I need json parsing, so I downloaded the Jansson library code. The project that Jansson generates when using Cmake wouldn't add as a reference to my Sphere project, because it targets Win32, so I created an empty Azure sphere library project, copied all the jansson code into it and messed with the defined variables until the project compiled.

Now I am trying to add that Jansson library to my HTTPS_Curl_Easy sample, however I cannot get it to be available in the project (It says jansson.h is not available): enter image description here

Two specific questions:

  1. In an azure Sphere library project, how do I tell it what to export? The project template had an Inc\Public folder - does the header file have to be in there? (mine isn't because the source wouldn't build with it in there)

  2. How should I add a reference to a library project in an Azure Sphere project? I right-clicked the project and clicked add->reference to add my jansson_sphere library project, but although it is in the project file it doesn't show in any dependency list that I could find.

Source for my project and my attempt to build Jansson is in github here: https://github.com/Joon/HTTPS_Curl_Easy

like image 731
Joon Avatar asked Nov 06 '22 14:11

Joon


1 Answers

To add an external library to an Azure Sphere build, you need to update the CMakeLists.txt file.

Below is an example of the CMakeLists.txt file which will work, and here is a link to a repository showing an external library which performs a delay and blinks LED1 on the MT3620 RDB.

https://github.com/AdamBaumgartner42/azsphere_ext_library

Updated CMakeLists.txt file

#  Copyright (c) Microsoft Corporation. All rights reserved.
#  Licensed under the MIT License.

cmake_minimum_required (VERSION 3.10)

project (azsphere_ext_library C)

azsphere_configure_tools(TOOLS_REVISION "21.07")
azsphere_configure_api(TARGET_API_SET "10")

# External Library Add
add_library(MyStaticLib STATIC delay.c)

# Create executable
add_executable (${PROJECT_NAME} main.c)

# add the external library to the "target_link_libraries" list
target_link_libraries (${PROJECT_NAME} MyStaticLib applibs pthread gcc_s c)

azsphere_target_hardware_definition(${PROJECT_NAME} TARGET_DIRECTORY "HardwareDefinitions/mt3620_rdb" TARGET_DEFINITION "template_appliance.json")
azsphere_target_add_image_package(${PROJECT_NAME})
like image 199
TechBaumgartner Avatar answered Nov 14 '22 04:11

TechBaumgartner