no image display after "fixing" Segmentation fault

65 views
Skip to first unread message

Marc Postrach

unread,
Jun 16, 2025, 8:26:09 AMJun 16
to bcm2835
Hi,

could someone give me a hint, on how to integrate des bcm Library.

Setup + Error

I run a program in C++ on a Raspberry Pi Zero that is suposed to show bmp images on an ePaper display. The display is connected via SPI. Program and pictures are located on the sd card on the pi.

When the programm is executed via SSH with  sudo, the program runs as desired. Without sudo or if the program is to be executed via cronjob, I get a segmentation fault. Cronjob is created as root with "sudo crontab -e". An entry under /etc/log/ with '*/5 * * * * root /home/marc/bcm2835-1.75/PicTest > 2>&1' also leads to seg-fault.

I was able to fix the Segfault error (at least the error message), but still the display of images fails.

What I've tried so far

  • Executed the instructions within "bcm2835.c" under "Running as root"
  • Updated operating system on Raspi to the latest version. Bookworm V12
  • libcap2 and libcap-dev installed or updated to the latest version (1:2.66-4+deb12u1)
  • Adds the user to the kmem group
  • reboot
  • Loaded and unzipped the latest build of the library bcm2835 (here 1.75)
  • Line "//#include..." in file /bcm2835/scr/bcm2835.h un-commented
  • ./configure
  • Make
  • sudo make check

Here I got severall error messages for the test program.

gcc  -g -O2   -o test test.o ./libbcm2835.a -lrt
/usr/bin/ld: ./libbcm2835.a(bcm2835.o): in function `bcm2835_has_capability':
/home/marc/bcm2835-1.75/src/bcm2835.c:140: undefined reference to `cap_get_proc'
/usr/bin/ld: /home/marc/bcm2835-1.75/src/bcm2835.c:144: undefined reference to `cap_get_flag'
/usr/bin/ld: /home/marc/bcm2835-1.75/src/bcm2835.c:146: undefined reference to `cap_free'
/usr/bin/ld: /home/marc/bcm2835-1.75/src/bcm2835.c:146: undefined reference to `cap_free'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:551: test] Error 1
make[2]: Leaving directory '/home/marc/bcm2835-1.75/src'
make[1]: *** [Makefile:851: check-am] Error 2
make[1]: Leaving directory '/home/marc/bcm2835-1.75/src'
make: *** [Makefile:369: check-recursive] Error 1x


I then added the lcap in "bcm2835/makefile" and "bcm2835/src/makefile" in line "LIBS = -lrt -lcap".

"sudo make check" then ran without an error message. For my program, I also linked the -lcap when compiling. Again, there were no error messages when compiling.

The program starts without sudo, i.e. with "./myApp" also works. However, when starting via cronjob, I don't get a segmentation fault, but the bmp file is not displayed. All writing and drawing functions (letters, lines, circles, etc.) work. Only the display of images fails. The function runs without an error message, but the screen remains white.

I have almost no idea about c/c++. At most, a basic understanding through coding in e.g. Python. So I placed some debug lines along the code to see, if it fails silently while running. As far as I can tell, the program runs through. Just without showing des bmp-images.

What else I tried

  • Granting root rights for "/dev/gpiomem" to me as a user

```
sudo groupadd gpio
sudo usermod -a -G gpio user_name
sudo grep gpio /etc/group
sudo chown root.gpio /dev/gpiomem
sudo chmod g+rw /dev/gpiomem

```
  • Assigning root rights for "/dev/mem" to me as a user as well
  • compiling 2 other libraries "lg Library" and "gpiod Library", but with the same results. Drawing functions are working, but no display of images. And both Libraries are pretty slow compared to bcm2835.

Question / Request

Can someone give me a hint on what I can try further.
I would be very grateful.
Of course I can post the output of the ssh session here, if i helps.

English is not my mother tongue. So I hope, what I wrote makes sense.

Thanks, Marc

mike james

unread,
Jun 18, 2025, 1:18:03 PMJun 18
to bcm2835
It makes sense but you have presented a very complex and confusing set
of symptoms.
There is nothing at all for us to single out as a problem.
You need to start from a fresh pi with fresh os, install bcm and check
that a demo program works both
using ssh and using chron
If you are using anything but basic GPIO you need to be running the
program with root privileges.
i.e. you need to use gpiomem.

Your problem starts much earlier than you are reporting and you have a
lot of extra "stuff" confusing
the issue.
mikej
PS what was causing the seg fault
Message has been deleted

Marc Postrach

unread,
Jun 20, 2025, 12:21:48 PMJun 20
to bcm2835
Hi Mike,

thank you for your reply and your time.
Sorry, I had tried to describe the problem as clearly as possible and would like to try again.

This is what I did

  • fresh os installed and updated (Bockworm)
  • download an unzip latest build of bcm2835 (here 1.75)
  • follow instructions within "bcm2835.c" under "Running as root"  (https://www.airspayce.com/mikem/bcm2835/index.html)
    • libcap2 and libcap-dev updated to the latest version (1:2.66-4+deb12u1)
    • Add user to the kmem group
    • reboot pi
    • un-comment line "//#include..." in file "/bcm2835/scr/bcm2835.h"
    • ./configure
  • dealing with "undefined reference" error messages when executing "make" and "sudo make check"
    • add "-lcap" in "bcm2835/makefile" and "bcm2835/src/makefile" in line "LIBS = -lrt -lcap"
    • make
    • sudo make check (no more error messages)
    • sudo make install
  • follow instructions from Waveshare for e-paper Display (https://www.waveshare.com/wiki/7.8inch_e-Paper_HAT#Working_with_Raspberry_Pi_.28SPI.29)
    • enable SPI an Raspberr pi (as said in the Instructions from Waveshare)
    • installing and compiling demo Code "TestApp" from Waveshare (no error messages)
    • sudo setcap cap_sys_rawio+ep TestApp

The following happens on executing Test app
  1. executing with sudo --> image.bmp is displayed | shapes and text are drawn
  2. executing without sudo --> image.bmp is displayed |  shapes and text are drawn
  3. executing via cronjob --> image.bmp is NOT displayed (no error message, just white screen) |  shapes and text are drawn

My Guess

Shapes and text get displayed. So the data-stream from Pi to Display via GPIO is working.
Images don't get displayed. Is it posible, that access to memory  where the image is located is  denied?
I could try to put image-data into the code (as array or something) to test this out.

I would still appreciate any hint on the topic.

Thanks, Marc

Mike McCauley

unread,
Jun 20, 2025, 12:36:09 PMJun 20
to bcm...@googlegroups.com
Is it possible your program does not have permissions to access the image file when it runs as “cron”?

In any case I don’t think this is a fault with bcm2835 library 

Cheers

Sent from my iPhone

On 20 Jun 2025, at 6:22 pm, Marc Postrach <marc_p...@posteo.de> wrote:

Hi Mike,
--
You received this message because you are subscribed to the Google Groups "bcm2835" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bcm2835+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/bcm2835/5a345f2d-8bf2-46af-a8be-8c3705be9e87n%40googlegroups.com.

mike james

unread,
Jun 20, 2025, 1:00:31 PMJun 20
to bcm2835
I'd agree that it has all the feeling of a permissions problem and cron doesn't usually run as root.
I'd also agree that it is unlikely to be due to the be bcm2835 library other than permissions.
mikej

Message has been deleted

Marc Postrach

unread,
Jul 4, 2025, 6:10:31 AMJul 4
to bcm2835
Hi Mike and Mike,

thanks for your feedback.
I just went back to my debugging problem and found that in the examplecode from waveshare a file (not the image) is accessed via an abbreviated path (./user....). 
After I had specified the complete path, the program ran through. Unfortunatly the wrong path did not lead to an error message.
As said, I dont do coding in c/c++. So with a prober IDE I might have been warned.

So, what I can take away for myself and what may help others is the step to integrate the lcap library in the make file correctly, as described in the previous post.
 
Thanks for your time and help,
Marc
Message has been deleted

mike james

unread,
Jul 8, 2025, 5:17:30 AMJul 8
to bcm2835
You said it yourself -- get an IDE.
I use VS Code - its free and it works very well in C and most other languages.
This means you only have to learn it once.

My other observation is that you should build incrementally and test as you go.
That way you find the error before it gets hidden in complexity.
Also, shameless plug, buy a copy of 
its written by my friend and I was the technical editor - it uses bcm2835 and VS Code.
Finally - after using bcm2835 for many years you need to know that I have found zero
bugs - so probability suggests that you start a bug hunt elsewhere :-)

mikej

Reply all
Reply to author
Forward
0 new messages