2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ライブラリの作り方

Last updated at Posted at 2018-11-18

Azure Sphereでライブラリを作成する手順です。
Azure Sphere SDKのバージョンは18.11で確認しました。(TP4.2.1はダメです。アップデートしましょう。)

プロジェクトを作る

新しいソリューションに、ライブラリを呼び出すアプリケーションのプロジェクトと、呼び出されるライブラリのプロジェクトを作成します。

  • MT3620App1 ... アプリケーションのプロジェクト。Blank Application for MT3620 RDB。
  • Library1 ... ライブラリのプロジェクト。Blank Static Library。

ファイル > 新規作成 > プロジェクト
image.png

ソリューションを右クリック > 追加 > 新しいプロジェクト
image.png

ソリューションエクスプローラーがこのようになっていれば正常です。

image.png

ライブラリにコードを追加

ライブラリのプロジェクトに含まれているLibrary1.hに宣言、Library1.cに定義を追記します。

Library1.h
# pragma once

int pow2(int a);
Library1.c
# include <Library1.h>

int pow2(int a)
{
	return a * a;
}

アプリケーションにライブラリ参照を追加

アプリケーションのプロジェクトに、ライブラリの参照を追加します。

参照を右クリック > 参照の追加 > Library1をチェック
image.png

参照にLibrary1が追加されていれば正常です。

image.png

アプリケーションからライブラリを呼び出す

main.c(断片)
...
# include <Library1.h>
...
int main(int argc, char *argv[])
{
...
    // Main loop
    const struct timespec sleepTime = {1, 0};
	int val = 0;
    while (!terminationRequired) {
        Log_Debug("%d %d\n", val, pow2(val));
		val++;
        nanosleep(&sleepTime, NULL);
    }
...
}

実行結果

image.png

配布するライブラリのファイル

2018/11/23追記

ライブラリを他者に配布するときのファイルは、ヘッダファイルとアーカイブファイル(ライブラリファイル)ですが、どちらもプロジェクトフォルダ配下にあります。

  • ヘッダーファイル ... Inc\Public\Library1.h
  • アーカイブファイル(Debugビルド) ... bin\ARM\Debug\libLibrary1.a
  • アーカイブファイル(Releaseビルド) ... bin\ARM\Release\libLibrary1.a

image.png
image.png

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?