Issues compiling example C programs

Applications, development tools, FPGA, C, WEB
Post Reply
jsch
Posts: 7
Joined: Fri May 27, 2022 9:41 pm

Issues compiling example C programs

Post by jsch » Fri May 27, 2022 10:13 pm

Hello, newbie here.
I am trying to run the trigger.c program shared in this post a while back

https://forum.redpitaya.com/viewtopic.php?t=355
(or on github at) https://github.com/Grozomah/trigger

I have a STEMlab 125-14 on which I have installed the latest stable SD card image. I followed the instructions for compiling and running C programs here https://redpitaya.readthedocs.io/en/lat ... .html#comc

However after cloning the RedPitaya repo, going to the Examples/C directory and trying to compile the example script with

Code: Select all

$ make digital_led_blink
I got an error:

Code: Select all

redpitaya/rp.h: No such file or directory found
.

I found this thread which seems to try to address this issue:
https://forum.redpitaya.com/viewtopic.php?t=1411,

After doing

Code: Select all

$ cd RedPitaya
$ make api
I get the output

Code: Select all

Install the project...
-- Install configuration: "Release"
-- Installing: /root/RedPitaya/build/lib/librp-hw.so
-- Up-to-date: /root/RedPitaya/build/include
-- Installing: /root/RedPitaya/build/include/rp_hw.h
-- Installing: /root/RedPitaya/build/lib/librp-hw.a
-- Up-to-date: /root/RedPitaya/build/include
-- Up-to-date: /root/RedPitaya/build/include/rp_hw.h
Going back to Examples/C and running

Code: Select all

$ make digitial_led_blink
again I get

Code: Select all

cc -g -std=gnu11 -Wall -Werror -I/opt/redpitaya/include  -L/opt/redpitaya/lib  digital_led_blink.c  -static -lrp -lrp-hw -lm -lstdc++ -lpthread -o digital_led_blink
/usr/bin/ld: cannot find -lrp-hw
I noticed that the compiler is looking under /opt, so instead I also tried doing

Code: Select all

gcc -g -std=gnu99 -I/root/RedPitaya/api/include/ -L/root/RedPitaya/api/lib/ -lrp -lm -o digital_led_blink digital_led_blink.c
This failed with

Code: Select all

fatal error: rp.h: No such file or directory
.
Any advice for how to properly compile these scripts would be very appreciated! Sorry in advance if the answer is obvious. Hopefully if I learn to compile digital_led_blink.c, then compiling the script I want to run (trigger.c) will be more straight forward. Thank you!

jsch
Posts: 7
Joined: Fri May 27, 2022 9:41 pm

Re: Issues compiling example C programs

Post by jsch » Sat May 28, 2022 1:53 am

EDIT:
I accidentally wrote that the include and lib paths I used were at

Code: Select all

/root/RedPitaya/api/
, but I meant

Code: Select all

/root/RedPitaya/build/
.

If I change the following lines in the Makefile like

Code: Select all

CFLAGS += -I/root/RedPitaya/build/include
LDFLAGS = -L/opt/RedPitaya/build/lib
I get the following error when I try to make $digital_led_blink.c"

Code: Select all

/usr/bin/ld: cannot find -lrp
/usr/bin/ld: cannot find -lrp-hw
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'digital_led_blink' failed
make: *** [digital_led_blink] Error 1
I have that

Code: Select all

$ ls /root/RedPitaya/build/lib/
librp.a  librp-hw.a  librp-hw.so  librp.so
and

Code: Select all

echo $LD_LIBRARY_PATH
/root/RedPitaya/build/lib

User avatar
redpitaya
Site Admin
Posts: 625
Joined: Wed Mar 26, 2014 7:04 pm

Re: Issues compiling example C programs

Post by redpitaya » Thu Jun 02, 2022 8:33 am

Please note that the instructions are in our documentation here; and they do work.
3.2.2.1. Compiling and running C applications
https://redpitaya.readthedocs.io/en/lat ... /comC.html

jsch
Posts: 7
Joined: Fri May 27, 2022 9:41 pm

Re: Issues compiling example C programs

Post by jsch » Mon Jun 20, 2022 7:40 pm

Hello, Thank you for the response. I have gone through the instructions in the provided link line by line on a rp with a fresh OS install and I get the following error when I try to compile the example script:

Code: Select all

# make digital_led_blink
cc -g -std=gnu11 -Wall -Werror -I/opt/redpitaya/include  -L/opt/redpitaya/lib  digital_led_blink.c  -static -lrp -lrp-hw -lm -lstdc++ -lpthread -o digital_led_blink
/usr/bin/ld: cannot find -lrp-hw
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'digital_led_blink' failed
make: *** [digital_led_blink] Error 1
Any help sorting this out would be greatly appreciated! Thank you in advance!

User avatar
M0JPI
Posts: 19
Joined: Wed Jun 15, 2022 8:06 pm
Location: Cumbria, UK

Re: Issues compiling example C programs

Post by M0JPI » Mon Jun 20, 2022 10:42 pm

I tried this on both the stable version 1.04-11 and the beta version 1.04-18.

I did find your error is produced with the stable version 1.04-11.

I've been using the beta version since it came out in April without any problems.
The examples compile and run on the beta version 1.04-18.

jsch
Posts: 7
Joined: Fri May 27, 2022 9:41 pm

Re: Issues compiling example C programs

Post by jsch » Mon Jun 20, 2022 10:57 pm

Hi M0JPI,

Thanks for the response. If I simply remove the -lrp-hw library from the compilation, it seems to compile and run fine. I guess the stable version just doesn't have the lrp-hw file?

User avatar
M0JPI
Posts: 19
Joined: Wed Jun 15, 2022 8:06 pm
Location: Cumbria, UK

Re: Issues compiling example C programs

Post by M0JPI » Mon Jun 20, 2022 11:03 pm

I'm not sure what the difference is, but both versions seem to include -lrp-hw. On the beta OS make produces the following result:

Code: Select all

# make digital_led_blink
cc -g -std=gnu11 -Wall -Werror -I/opt/redpitaya/include  -L/opt/redpitaya/lib  digital_led_blink.c  -static -lrp -lrp-hw -lm -lstdc++ -lpthread -o digital_led_blink

jsch
Posts: 7
Joined: Fri May 27, 2022 9:41 pm

Re: Issues compiling example C programs

Post by jsch » Mon Jun 20, 2022 11:31 pm

I see, thank you for checking that the beta version works. I guess I'm now onto the bigger task of compiling the trigger.c script described in my original post and found here https://github.com/Grozomah/trigger or described in this post from 2014 https://forum.redpitaya.com/viewtopic.php?t=355. Cloning the repo and trying to run

Code: Select all

$ make trigger
, I get the following errors:

Code: Select all

gcc   trigger.o   -o trigger
/usr/bin/ld: error: trigger uses VFP register arguments, trigger.o does not
/usr/bin/ld: failed to merge target specific data of file trigger.o
trigger.o: In function `main':
/home/grozolinux/RedPitaya/src/utils/trigger/trigger.c:31: undefined reference to `osc_fpga_init'
/home/grozolinux/RedPitaya/src/utils/trigger/trigger.c:42: undefined reference to `osc_fpga_set_trigger_delay'
/home/grozolinux/RedPitaya/src/utils/trigger/trigger.c:46: undefined reference to `osc_fpga_reset'
/home/grozolinux/RedPitaya/src/utils/trigger/trigger.c:53: undefined reference to `osc_fpga_cnv_v_to_cnt'
/home/grozolinux/RedPitaya/src/utils/trigger/trigger.c:61: undefined reference to `osc_fpga_arm_trigger'
/home/grozolinux/RedPitaya/src/utils/trigger/trigger.c:62: undefined reference to `osc_fpga_set_trigger'
/home/grozolinux/RedPitaya/src/utils/trigger/trigger.c:87: undefined reference to `osc_fpga_get_sig_ptr'
/home/grozolinux/RedPitaya/src/utils/trigger/trigger.c:115: undefined reference to `osc_fpga_exit'
/home/grozolinux/RedPitaya/src/utils/trigger/trigger.c:117: undefined reference to `g_osc_fpga_reg_mem'
collect2: error: ld returned 1 exit status
<builtin>: recipe for target 'trigger' failed
make: *** [trigger] Error 1
The fpga_osc.h file included in trigger.c seems to declare all the functions that the compilation complains about as "undefined references". If somebody more knowledgeable about C compilation could offer some advice, that would be very appreciated. Sorry if the question is basic, I am not well versed in these things!

User avatar
M0JPI
Posts: 19
Joined: Wed Jun 15, 2022 8:06 pm
Location: Cumbria, UK

Re: Issues compiling example C programs

Post by M0JPI » Tue Jun 21, 2022 11:20 am

Today is a learning day for me, the problem seems to be that the Github repository included the compiled output, and some of it was build for ARM soft-float and there was a mixture of Arm hard-float and soft-float. The Red Pitaya boards all use ARM hard-float.

Deleting the previously complied output still in the repo fixed the problem for me and allows make to compile make (all).

Code: Select all

root@rp:/home/redpitaya/trigger# rm trig *.o
root@rp:/home/redpitaya/trigger# make
gcc -c -g -std=gnu99 -Wall -Werror -DVERSION=0.00-0000 -DREVISION=devbuild trigger.c -o trigger.o
gcc -c -g -std=gnu99 -Wall -Werror -DVERSION=0.00-0000 -DREVISION=devbuild fpga_osc.c -o fpga_osc.o
gcc -o trig trigger.o fpga_osc.o -g -std=gnu99 -Wall -Werror -DVERSION=0.00-0000 -DREVISION=devbuild -lm -lpthread
root@rp-f03e70:/home/redpitaya/trigger# ls
fpga_osc.c  fpga_osc.h  fpga_osc.o  Makefile  README.md  trig  trigger.c  trigger.o  version.h
root@rp-f03e70:/home/redpitaya/trigger# ./trig
-9 -4 -10 -13 -4 -8 -5 -7 -3 -5 -7 -10
-7 0 8 -5 0 1 -8 -1 3 -5 -3 5
-10 -12 -8 -5 -15 -10 -4 -14 0 -8 0 -10
-10 -6 -3 -7 -13 -5 -4 -10 -10 -7 -6 -11
-12 -13 -7 -4 -13 0 -1 -8 -4 3 -4 1
3 -20 -31 -46 -61 -52 -45 -37 -23 -16 -31 -24
-5 -1 -7 -10 -6 1 -5 -12 -3 -5 -8 -13
-10 -4 -6 -10 -2 -4 -8 -13 -10 -8 -5 3
0 -17 -26 -46 -56 -49 -54 -39 -35 -32 -22 -33
-11 -39 -52 -70 -73 -79 -61 -57 -44 -42 -39 -45

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 1 guest