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

Joo*_*oon 5 c azure iot jansson azure-sphere

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

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

两个具体问题:

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

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

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

小智 1

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

下面是一个可以运行的 CMakeLists.txt 文件的示例,这里是一个存储库的链接,显示了一个外部库,该库在 MT3620 RDB 上执行延迟并闪烁 LED1。

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})
Run Code Online (Sandbox Code Playgroud)