mayl

mayl

I have a project using circuits_i2c and I want to be able to run the project on my PC with circuits_sim. Following the documentation I wound up with this in my config.exs (qemu is the MIX_TARGET I want to use the simulated i2c bus for:

if config_target() == :qemu do
  config :circuits_i2c, default_backend: CircuitsSim.I2C.Backend
  config :circuits_sim,
  config: [
    {CircuitsSim.Device.MCP23008, bus_name: "i2c-0", address: 0x20},
  ]
end

This works for iex and I can see the MIX_TARGET take effect:

✦ ❯ iex -S mix
Generated circuits_sim_test app
Erlang/OTP 26 [erts-14.2.3] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.16.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Circuits.I2C.bus_names
[]
✦ ❯ MIX_TARGET=qemu iex -S mix
Erlang/OTP 26 [erts-14.2.3] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1] [jit:ns]

Interactive Elixir (1.16.2) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> Circuits.I2C.bus_names
["i2c-0"]
iex(2)>

However, for releases built like this:

✦ ❯ MIX_TARGET=qemu mix release

Running the resulting release gives the following error, where circuits_i1c appears to try to load the NIF despite being apparently configured to use the circuits_sim backend:

✦ ❯ _build/qemu_dev/rel/circuits_sim_test/bin/circuits_sim_test start_iex
=CRASH REPORT==== 13-Aug-2025::18:14:17.622342 ===
  crasher:
    initial call: kernel:init/1
    pid: <0.675.0>
    registered_name: []
    exception exit: {on_load_function_failed,'Elixir.Circuits.I2C.Nif',
                        {error,
                            {load_failed,
                                "Failed to load NIF library: '/home/larry/projects/circuitsSimIssue/circuits_sim_test/_build/qemu_dev/rel/circuits_sim_test/lib/circuits_i2c-2.1.0/priv/i2c_nif.so: cannot open shared object file: No such file or directory'"}}}
      in function  init:run_on_load_handlers/0
      in call from kernel:init/1 (kernel.erl, line 227)
    ancestors: [kernel_sup,<0.668.0>]
    message_queue_len: 0
    messages: []
    links: [<0.670.0>]
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 610
    stack_size: 28
    reductions: 234
  neighbours:

=SUPERVISOR REPORT==== 13-Aug-2025::18:14:17.622504 ===
    supervisor: {local,kernel_sup}
    errorContext: start_error
    reason: {on_load_function_failed,'Elixir.Circuits.I2C.Nif',
                {error,
                    {load_failed,
                        "Failed to load NIF library: '/home/larry/projects/circuitsSimIssue/circuits_sim_test/_build/qemu_dev/rel/circuits_sim_test/lib/circuits_i2c-2.1.0/priv/i2c_nif.so: cannot open shared object file: No such file or directory'"}}}
    offender: [{pid,undefined},
               {id,on_load},
               {mfargs,{proc_lib,start_link,[kernel,init,[on_load]]}},
               {restart_type,transient},
               {significant,false},
               {shutdown,2000},
               {child_type,worker}]

=CRASH REPORT==== 13-Aug-2025::18:14:17.623120 ===
  crasher:
    initial call: application_master:init/4
    pid: <0.667.0>
    registered_name: []
    exception exit: {{shutdown,
                      {failed_to_start_child,on_load,
                       {on_load_function_failed,'Elixir.Circuits.I2C.Nif',
                        {error,
                         {load_failed,
                          "Failed to load NIF library: '/home/larry/projects/circuitsSimIssue/circuits_sim_test/_build/qemu_dev/rel/circuits_sim_test/lib/circuits_i2c-2.1.0/priv/i2c_nif.so: cannot open shared object file: No such file or directory'"}}}}},
                     {kernel,start,[normal,[]]}}
      in function  application_master:init/4 (application_master.erl, line 142)
    ancestors: [<0.666.0>]
    message_queue_len: 1
    messages: [{'EXIT',<0.668.0>,normal}]
    links: [<0.666.0>,<0.665.0>]
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 987
    stack_size: 28
    reductions: 208
  neighbours:

=INFO REPORT==== 13-Aug-2025::18:14:17.623386 ===
    application: kernel
    exited: {{shutdown,
                 {failed_to_start_child,on_load,
                     {on_load_function_failed,'Elixir.Circuits.I2C.Nif',
                         {error,
                             {load_failed,
                                 "Failed to load NIF library: '/home/larry/projects/circuitsSimIssue/circuits_sim_test/_build/qemu_dev/rel/circuits_sim_test/lib/circuits_i2c-2.1.0/priv/i2c_nif.so: cannot open shared object file: No such file or directory'"}}}}},
             {kernel,start,[normal,[]]}}
    type: permanent

Kernel pid terminated (application_controller) ("{application_start_failure,kernel,{{shutdown,{failed_to_start_child,on_load,{on_load_function_failed,'Elixir.Circuits.I2C.Nif',{error,{load_failed,\"Failed to load NIF library: '/home/larry/projects/circuitsSimIssue/circuits_sim_test/_build/qemu_dev/rel/circuits_sim_test/lib/circuits_i2c-2.1.0/priv/i2c_nif.so: cannot open shared object file: No such file or directory'\"}}}}},{kernel,start,[normal,[]]}}}")

Crash dump is being written to: erl_crash.dump...done

I want to be able to build a release using circuits_sim, because I am testing more than just this elixir app in qemu and my higher level nix build that produces that VM needs a release as input. Is there a way to make that work?

Showing Posts 1 to 5

fhunleth

fhunleth

Co-author of Nerves

Hmm. I think that I only have guesses since I’m not sure what you have configured for MIX_TARGET=qemu. Would it be possible for you to create a reproduction case for this and post an issue to the circuits_sim GitHub? I’m quite sure there could at least be a better error message if there is, indeed, an error.

mayl

mayl OP

Hi Frank, yes of course I’d really appreciate you taking a look at it.
Here’s a pretty minimal reproduction case. I use Nix, but I think if you ignore that and just go to the mix project in there it should work the same:
https://github.com/mayl/circuits_sim_release

fhunleth

fhunleth

Co-author of Nerves

Thanks. I understand your setup now what was happening.

Could you update your mix dependencies to use the branch at Support builds that completely exclude I2CDev support by fhunleth · Pull Request #211 · elixir-circuits/circuits_i2c · GitHub and confirm that it works like you were expecting? E.g.,

{:circuits_i2c, github: "elixir-circuits/circuits_i2c", branch: "dont-load-nif-if-not-built", override: true}
mayl

mayl OP

I just have my small test project here to try it on, so I’ll report back if my bigger project doesn’t work but that seems to fix it! Thanks so much for your help!

I’m definitely going to look over your branch to try to understand what you needed to modify to make this work. I’m not using the other circuits_sim backends currently, but do you think it’s likely they would have a similar issue?

fhunleth

fhunleth

Co-author of Nerves

Yes, they’ll have the exact same issue.

What you ran into turned out to be due to the logic controlling whether to build the NIF when it’s not used. The Elixir module using the NIF used to lazy load it and then give you an error. I had to remove the lazy NIF loading since there were a lot of issues with it in practice. I didn’t realize that caused the regression with circuits_sim and releases. The PR completely removes everything involved with the NIF when it’s unused, so it’s not even possible to get the error.

As another benefit, non-Nerves/non-Linux users of Circuits.I2C (and eventually the others) won’t even have a single Elixir module that’s needed for Linux-support compiled now. The C code was already gone, but I got the feedback that just having the associated Elixir modules there wasn’t ideal.

Thanks for reporting the issue. The other Elixir Circuits libraries will get the same treatment as I get time.

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
widianto
I think I’ve found a small improvement I could contribute to &lt;%= web_namespace %&gt;.CoreComponents (installer/templates/phx_web/compo...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
aseigo
ICal is a library for interacting with iCalendar data. It parses iCalendars into typed Elixir structs via ICal.from_ics, and can prepare ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews