0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめてね AtomVM(2) コンパイル時の関数がないという警告の扱い方

0
Last updated at Posted at 2026-04-22

はじめに

AtomVM で Lチカをしてみました。その様子を はじめてね AtomVM(1) ESP32でLチカ に書いてます。このこときのコンパイル時に割としっかりした警告が出てました。これは何なのか、無視して良かったのか調べてみました。
なお、これは version 0.6.6 の話ですが、2026-04-22 現在 0.7.0-alpha が出てるのですぐに役に立たなくなるかもです。

コンパイルで何が起こったか

Lチカのプログラムは公式のサンプルプログラム集 atomvm_exampleselixir/Blinky のものです。このアプリケーションプログラム elixir/Blinky/lib/Blinky.ex をそのままコンパイルするとこうなります。

% mix compile
Compiling 1 file (.ex)
    warning: using single-quoted strings to represent charlists is deprecated.
    Use ~c"" if you indeed want a charlist or use "" instead.
    You may run "mix format --migrate" to change all single-quoted
    strings to use the ~c sigil and fix this warning.
    
 33      :io.format('Setting pin ~p ~p~n', [pin, level])
                    ~
    
    └─ lib/Blinky.ex:33:16

    warning: GPIO.digital_write/2 is undefined (module GPIO is not available or is yet to be defined). Make sure the module name is correct and has been specified in full (or that an alias has been defined)
    
 34      GPIO.digital_write(pin, level)
              ~
    
    └─ lib/Blinky.ex:34:10: Blinky.loop/2

    warning: :atomvm.platform/0 is undefined (module :atomvm is not available or is yet to be defined)
    
 48      case :atomvm.platform() do
                      ~
    
    └─ lib/Blinky.ex:48:18: Blinky.pin/0
    └─ lib/Blinky.ex:57:18: Blinky.platform_gpio_setup/0

    warning: GPIO.set_pin_mode/2 is undefined (module GPIO is not available or is yet to be defined). Make sure the module name is correct and has been specified in full (or that an alias has been defined)
    
 58        :esp32 -> GPIO.set_pin_mode(pin(), :output)
                          ~
    
    └─ lib/Blinky.ex:58:22: Blinky.platform_gpio_setup/0
    └─ lib/Blinky.ex:59:22: Blinky.platform_gpio_setup/0
    └─ lib/Blinky.ex:65:18: Blinky.platform_gpio_setup/0

    warning: GPIO.init/1 is undefined (module GPIO is not available or is yet to be defined). Make sure the module name is correct and has been specified in full (or that an alias has been defined)
    
 64              GPIO.init(pin)
                      ~
    
    └─ lib/Blinky.ex:64:18: Blinky.platform_gpio_setup/0

Generated Blinky app

このうち最初の警告は文字列の表記の問題です。charlist を 'Setting pin ~p ~p~n' と書くのは古い書き方だから改めるように、それも mix format --migrate で直せる旨を言ってます。これはまあ軽微です。

問題は次以降で、以下の4つの関数が定義されていないと警告を出してます。

  • GPIO.digital_write/2 is undefined
  • :atomvm.platform/0 is undefined
  • GPIO.set_pin_mode/2 is undefined
  • GPIO.init/1 is undefined

この warning が出る原因は、コンパイラが module GPIO is not available or is yet to be definedmodule :atomvm is not available or is yet to be defined のように GPIO モジュールと :atomvm モジュールが有効でないかまだ定義されてないと言ってます。

これを解決しようとして四苦八苦しましたが、結局のところは

  • 解決せずに警告を無視する
  • 警告が出ないように設定する

で済ますことができてます。後者は lib/Blinky.ex の先頭で @compile {:no_warn_undefined, [GPIO, :atomvm]} を宣言することで実現できます。
この後 mix atomvm.packbeammix atomvm.esp32.flash して Lチカ自体はいごきました。しかしモジュールがなくてそのモジュールの関数がなくてなんで大丈夫なんだろうと思うところです。

警告が出たモジュールと関数はどうなってるのか

これはライブラリを適切に入れておくと avm_deps/atomvmlib-v0.6.6.avm に存在してます。これに入ってるモジュール(とその中の関数)はコンパイラには見えず、コンパイル時には解決できなくて warning が出てしまいます。出ますが packbeam した実行形式には存在しているので、実行は可能になります。
これ、

  • packbeam するときにリンカが頑張ってリンクされている
  • 実行時にモジュール名・関数名を解決してる

のどちらかと思います。が、私にはわかりません。最終的にはちゃんとした実行形式になるという、なんともわかりにくい状態になってます。母艦のPCでコンパイルする際に全部解決できているとありがたいのですがね。

参考文献

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?