2
1

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.

Catch2 IAR EWARM でビルドする方法

Last updated at Posted at 2018-01-08

これは何?

Catch を IAR Embedded Workbench でビルドする方法です。

結論

コンパイルはできます。
私が使用した無償評価版は 32KiB制限があり、リンクできませんでした。

実験環境

  • IAR EWARM 8.20.2 無償評価版
  • Windows 10 64bit版

必要な設定

プロジェクトの設定

  • 一般オプション > ライブラリ設定 > ライブラリ > フル を選択。
    ノーマルだと、ビルドエラーになります。Catch が fstream を使用するので、必須。
  • C/C++コンパイラ > 言語1 > C++オプション > 例外を有効にする にチェック。
    Catch が noexcept 修飾を使用しています。この解釈に必要です。
    CATCH_CONFIG_FAST_COMPILE を指定して例外を無効にしても、このキーワードを解釈するために必要になります。

コンパイルスイッチ(toggle)

次の二つが必要

main.c
# define CATCH_CONFIG_COLOUR_NONE
# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS

コードサイズ

下記コードをビルドして、 120キロオーバーです。

main.c
# define CATCH_CONFIG_RUNNER
# define CATCH_CONFIG_COLOUR_NONE
# define CATCH_CONFIG_NO_POSIX_SIGNALS
# include "catch.hpp"

unsigned int Factorial( unsigned int number ) {
    return number <= 1 ? number : Factorial(number-1)*number;
}

TEST_CASE( "Factorials are computed", "[factorial]" ) {
    REQUIRE( Factorial(1) == 1 );
    REQUIRE( Factorial(2) == 2 );
    REQUIRE( Factorial(3) == 6 );
    REQUIRE( Factorial(10) == 3628800 );
}

int main( int argc, char* argv[] ) {
    int result = Catch::Session().run(0,NULL);
    return result;
}

ビルドメッセージは下記

エラー[Og008]: Code size limit exceeded. 122 988 code bytes is more than the limit of 32 768 bytes. 

コードサイズが変わらないかと思い、下記のコンパイルスイッチも追加したが変化なし。考えてみたら、未使用の機能はテンプレートが実体化されず、コードサイズに影響ないのは当然でした。

main.c
# define CATCH_CONFIG_NOSTDOUT
# define CATCH_CONFIG_FAST_COMPILE
# define CATCH_CONFIG_DISABLE_MATCHERS

参考情報

List of platforms/compilers known to work? に試した人のコメントがあります。

ここを見ると、ヒープ、スタックサイズの調整と、tiemer 関数の実装が必要です。
ここは、ターゲットマイコン毎に変わるところなので、さもありなん。

感想

Cortex-M 系マイコンで使用できそうな予感。
std::cout から UART に差し替えて見て、どんな感じか試したいけど、どうするかなぁ。

2
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?