techyian / MMALSharp

C# wrapper to Broadcom's MMAL with an API to the Raspberry Pi camera.
MIT License
195 stars 33 forks source link

Instance access - liblibbcm_host.so: cannot open shared object file: No such file or directory #125

Closed thnk2wn closed 4 years ago

thnk2wn commented 4 years ago

When I reference MMALCamera.Instance I get the following exception.

Unhandled exception. System.DllNotFoundException: Unable to load shared library 'libbcm_host.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibbcm_host.so: cannot open shared object file: No such file or directory
   at MMALSharp.Native.BcmHost.bcm_host_init()
   at MMALSharp.MMALCamera..ctor()
   at MMALSharp.MMALCamera.<>c.<.cctor>b__28_0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at MMALSharp.MMALCamera.get_Instance()

The camera is enabled and I was able to test it via raspistill -o image.jpg. Is there something else I have to install or configure on the device to use this? Ideas?

techyian commented 4 years ago

I'm not overly familiar with docker and have never tried running the library in a container, but does the following help? https://github.com/skonagaya/RPi-Streamer/blob/master/Dockerfile#L75. Symlinks are being made to /usr/lib/ which I suspect is so that application can view the relevant libraries needed. Unsure whether you'll need all of them but it might put you in the right direction?

thnk2wn commented 4 years ago

Thanks, that helps. Figured I might need some volume mounts added. I also see others with Dockerfile steps like:

RUN apt-get install libraspberrypi-bin -y
RUN usermod -a -G video root

I'll do some research, just wasn't sure what all dependencies this library had in terms of file access, permissions, etc. that might need to be accounted for when running containerized.

techyian commented 4 years ago

Off the top of my head, I think it's libbcm_host.so and libmmal.so the library needs access to. Let me know how you get on. On a Raspbian based OS libraspberrypi-bin should already be installed but you might like to install that if running on Ubuntu for example as it gives you access to useful VideoCore utilities.

thnk2wn commented 4 years ago

I added -v /opt/vc/lib:/opt/vc/lib into my docker run command and now the original error went away.

Now I have a similar one but for libmmal.so. I see that in the same location so I'm not sure why that's an issue unless it's with a dependency elsewhere.

System.DllNotFoundException: Unable to load shared library 'libmmal.so' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: liblibmmal.so: cannot open shared object file: No such file or directory
   at MMALSharp.Native.MMALComponent.mmal_component_create(String name, IntPtr* comp)
   at MMALSharp.MMALComponentBase.CreateComponent(String name)
   at MMALSharp.MMALComponentBase..ctor(String name)
   at MMALSharp.Components.MMALCameraComponent..ctor()
   at MMALSharp.MMALCamera..ctor()
   at MMALSharp.MMALCamera.<>c.<.cctor>b__28_0()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at MMALSharp.MMALCamera.get_Instance()

I also set LD_DEBUG=all and can dump that if helpful.

thnk2wn commented 4 years ago

I got it working. I had to add ENV LD_LIBRARY_PATH /opt/vc/lib to my Dockerfile and I added some additional volume mounts.

It did appear to silently fail when capturing the image and specifying a path that didn't exist but I didn't have the destination (/home/pi/motion-media). mounted at that point.

docker run \
    --privileged \
    -v /opt/vc/lib:/opt/vc/lib \
    -v /home/pi/motion-media:/home/pi/motion-media \
    -d \
    --name $name \
    $username/$name:latest
techyian commented 4 years ago

Excellent, glad it's working for you.