如何在 Azure Sphere Visual Studio 项目中添加库依赖项?

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

我正在构建一个 Azure Sphere C 应用程序,从 HTTPS_Curl_Easy 示例项目开始。我需要json解析,所以我下载了Jansson库代码。 Jansson 在使用 Cmake 时生成的项目不会添加为对我的 Sphere 项目的引用,因为它针对 Win32,所以我创建了一个空的 Azure sphere 库项目,将所有 jansson 代码复制到其中并弄乱了定义的变量,直到项目编译。

现在我正在尝试将该 Jansson 库添加到我的 HTTPS_Curl_Easy 示例中,但是我无法在项目中使用它(它说 jansson.h 不可用):

两个具体问题:

  1. 在 azure Sphere 库项目中,如何告诉它导出什么?项目模板有一个 Inc\Public 文件夹——头文件必须在里面吗? (我的不是因为源代码不会在那里构建)

  2. 我应该如何在 Azure Sphere 项目中添加对库项目的引用?我右键单击该项目并单击添加-> 引用以添加我的 jansson_sphere 库项目,但尽管它在项目文件中,但它没有显示在我能找到的任何依赖项列表中。

我的项目源代码和我构建 Jansson 的尝试在 github 此处:https://github.com/Joon/HTTPS_Curl_Easy

要将外部库添加到 Azure Sphere 构建,您需要更新 CMakeLists.txt 文件。

下面是一个 CMakeLists.txt 文件的例子,这里是一个 link 到一个存储库,显示一个执行延迟和 blinks LED1 的外部库在 MT3620 RDB 上。

https://github.com/AdamBaumgartner42/azsphere_ext_library

已更新 CMakeLists.txt 文件

#  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})