plusuncold
Posts: 9
Joined: Mon Jan 28, 2013 1:24 am

'undefined reference to 'mbox_open()'

Wed Jul 01, 2015 1:37 pm

I'm attempting to use the GPU_FFT library and when I try to use the mbox_open() function in mailbox.h I get a compile error
undefined reference to 'mbox_open()
I've included the following libraries:
-lasound -ldl -lrt -lm

The last three are used in the example hello_fft.bin makefile
Last edited by plusuncold on Thu Sep 03, 2015 3:02 pm, edited 2 times in total.

User avatar
PeterO
Posts: 5958
Joined: Sun Jul 22, 2012 4:14 pm

Re: Using GPU_FFT in Qt 'undefined reference to 'mbox_open()

Wed Jul 01, 2015 1:42 pm

I'm not in front of a PI right now.... But from memory you need to link against the appropriate libraries in /opt/vc/lib as well.

And to be pedantic you aren't getting a compiler error, you are getting a linker error.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
Paeryn
Posts: 3023
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Using GPU_FFT in Qt 'undefined reference to 'mbox_open()

Wed Jul 01, 2015 1:48 pm

mbox_open() is defined in mailbox.c, and gpu_fft_prepare() is in gpu_fft.c both from the hello_fft directory are you compiling and linking in those too? I don't think they are in any library, just example source files.
She who travels light — forgot something.

User avatar
PeterO
Posts: 5958
Joined: Sun Jul 22, 2012 4:14 pm

Re: Using GPU_FFT in Qt 'undefined reference to 'mbox_open()

Wed Jul 01, 2015 1:51 pm

Paeryn wrote:mbox_open() is defined in mailbox.c, and gpu_fft_prepare() is in gpu_fft.c both from the hello_fft directory are you compiling and linking in those too? I don't think they are in any library, just example source files.
Indeed, that as well :-)
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

plusuncold
Posts: 9
Joined: Mon Jan 28, 2013 1:24 am

Re: Using GPU_FFT in Qt 'undefined reference to 'mbox_open()

Wed Jul 01, 2015 2:20 pm

All the source files from /opt/vc/src are imported into the project.
Last edited by plusuncold on Thu Sep 03, 2015 3:13 pm, edited 2 times in total.

User avatar
PeterO
Posts: 5958
Joined: Sun Jul 22, 2012 4:14 pm

Re: Using GPU_FFT in Qt 'undefined reference to 'mbox_open()

Wed Jul 01, 2015 2:28 pm

Are you sure all the C source files are being compiled and linked into the final binary ?
Can you post the qmake output ?

ISTR there's some "magic" needed to compile and link "C" code into "C++" applications ? (Something to do with name mangling ?)

Note I'm NOT a C++ programmer !

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
Paeryn
Posts: 3023
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Using GPU_FFT in Qt 'undefined reference to 'mbox_open()

Wed Jul 01, 2015 4:44 pm

PeterO wrote:ISTR there's some "magic" needed to compile and link "C" code into "C++" applications ? (Something to do with name mangling ?)
The headers as given won't handle C vs C++ naming differences. Either :-

I) The two .c files need renaming .cpp, or
II) Make sure the .c files are compiled with g++ not gcc (g++ assumes .c are C++ files, gcc doesn't), or
III) Add code to the corresponding header files so that C++ will use vanilla C naming rather than the C++ mangling.

If doing (III) then at the start of the C header files add

Code: Select all

#ifdef __cplusplus
extern "C" {
#endif
and at the end add

Code: Select all

#ifdef __cplusplus
}
#endif
This will force C++ to use C naming for the functions.
She who travels light — forgot something.

User avatar
ab1jx
Posts: 885
Joined: Thu Sep 26, 2013 1:54 pm
Location: Heath, MA USA
Contact: Website

Re: 'undefined reference to 'mbox_open()'

Wed Jul 12, 2017 2:16 am

It looks like this has never been formally packaged. I've had to include 4 of the original C files in my makefile so far chasing down undefined references. mailbox.c gpu_fft.c gpu_fft_base.c and then gpu_fft_twiddles.c which led to a header, I don't know where it will end.

I was attracted to the idea of using the GPU instead of sticking with fftw, but maybe I should have opted for the more portable approach. I'm just beginning an attempt at a GUI SDR program, like gqrx but all in C. I really don't know what I'm doing and I'm not up to making a library. Maybe a note should be added to gpu_fft.txt that this is experimental, I'm thinking of the assembled gpu/qpu stuff that needs to be included too.

User avatar
PeterO
Posts: 5958
Joined: Sun Jul 22, 2012 4:14 pm

Re: 'undefined reference to 'mbox_open()'

Wed Jul 12, 2017 7:32 am

ISTR the last time I looked at this the the GPU FFT was not that much faster that fftw.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
ab1jx
Posts: 885
Joined: Thu Sep 26, 2013 1:54 pm
Location: Heath, MA USA
Contact: Website

Re: 'undefined reference to 'mbox_open()'

Wed Jul 12, 2017 12:40 pm

Yes, thanks, somewhere I've seen the claim that it's 10 times as fast, but also lower precision. I was hoping to use it with an RTL2832 dongle which only does 8 bit unsigned (that's all the A/D is capable of). I don't know if one imprecision would mask the other or combine with it to be mostly unusable.

Oh yes, in /opt/vc/src/hello_pi/hello_fft/gpu_fft.txt it says "ten times more data throughput" and also "FFTW is still one order of magnitude more accurate". It also says "GPU_FFT is an FFT library" which it doesn't seem to quite be yet. Was this somebody's thesis project by any chance?

Putting the time into something that uses fftw instead might make it portable to more other hardware. Gqrx barely works sometimes but it's based on Gnuradio which is a huge amount of bloat partly implemented in Python.

I don't know, my interest (this week) is in doing SETI. I've had the rtl_sdr suite around for a few years and used it some. Rtl_power in it does some of what I want, and there are a couple forks called rtl_power_fftw. What I want to do, which would probably involve another fork, is to monitor like rtl_power but for any signals over a certain threshold do an IQ recording. Then a human would try different demodulation schemes to listen to those. I don't know anywhere near enough about SDR to write such a thing, yet anyway.

User avatar
ab1jx
Posts: 885
Joined: Thu Sep 26, 2013 1:54 pm
Location: Heath, MA USA
Contact: Website

Re: 'undefined reference to 'mbox_open()'

Thu Jul 13, 2017 1:42 pm

My workaround for now was to make a backup tarball of /opt/vc/src/hello_pi/hello_fft and trash the originals by experimenting with them. I used a stream of interleaved IQ bytes recorded to a file as a data source and in hello_fft.c changed:

Code: Select all

//            for (i=0; i<N; i++) base[i].re = base[i].im = 0;
            for (i=0; i<N; i++) {
              base[i].re = fgetc(ipf);
              base[i].im = fgetc(ipf);
            }
so instead of initializing to zeroes actual data gets read in. Then after the fft I added

fprintf(opf,"%f\t%f\n",base.re,base.im);

to get data back out as a tab-delimited file. It looks more random than what I was hoping for

Code: Select all

1043380.000000  1043205.000000
-954.748291     174.672623
-90.719696      -299.026367
718.133972      -1055.569214
-141.058105     -437.061279
354.780853      21.569679
254.175034      -599.849304
134.783478      132.473999
698.624268      -41.606354
-248.551239     562.872131
-81.911880      -109.841980
-260.412109     150.732056
223.794418      -239.976791
-280.998993     -548.337036
-218.571442     -531.792419
-950.497742     105.562218
I haven't done anything with windowing yet, and the IQ data was of an antenna pointed at quiet sky. It was reasonably fast:

Code: Select all

./hello_fft.bin 13 5
N set to 8192
rel_rms_err = 2.3e+04, usecs = 748, k = 0
Under a millisecond for 5 iterations of a bigger FFT than I expect to need. I guess I expected the output to look more like bins.

User avatar
PeterO
Posts: 5958
Joined: Sun Jul 22, 2012 4:14 pm

Re: 'undefined reference to 'mbox_open()'

Thu Jul 13, 2017 1:56 pm

IMO you won't get anything useful from just looking at rows of numbers. You need to get a graphical plot to make any sense of the data. gnuplot will help you to plot the input and output data sets.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
ab1jx
Posts: 885
Joined: Thu Sep 26, 2013 1:54 pm
Location: Heath, MA USA
Contact: Website

Re: 'undefined reference to 'mbox_open()'

Thu Jul 13, 2017 2:14 pm

Well, I did plots, I just wasn't entirely happy with them so I didn't post them.
junk.gif
junk.gif (7.06 KiB) Viewed 4593 times
as xy, then as yt
junk2.gif
junk2.gif (7.9 KiB) Viewed 4593 times
I'm not sure what a good test signal would be, maybe something like a sweep generator or chirp. I don't have one but I can probably write something. A sine wave is going to be monotonic. Maybe something like the FM broadcast band.
The second one was from doing

Code: Select all

plot 'fftout.txt' using 1,
  'fftout.txt' using 2

User avatar
PeterO
Posts: 5958
Joined: Sun Jul 22, 2012 4:14 pm

Re: 'undefined reference to 'mbox_open()'

Thu Jul 13, 2017 3:50 pm

A sine wave is exactly the thing you need as a test input. It's one of the few things where you can predict what the fft output should actually be.

Have you looked at this: http://www.peteronion.org.uk/FFT/FastFourier.html

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
ab1jx
Posts: 885
Joined: Thu Sep 26, 2013 1:54 pm
Location: Heath, MA USA
Contact: Website

Re: 'undefined reference to 'mbox_open()'

Fri Jul 14, 2017 4:38 am

No, I hadn't seen that. I was doing a Google search to see if this had been put into a library and found the author's page at http://www.aholme.co.uk/GPU_FFT/Main.htm Linked toward the bottom of that is a You-tube video of a working panadaptor running on a Pi: https://www.youtube.com/watch?v=0IZxzm4R1bo

He's (Peter Onion) running it on 40 meters with some RF hardware. I'd like to see it work with a cheap $20 standard RTL2832 dongle, which could in turn be used with a upconverter for HF. Interesting project, sort of what I was trying to do. I've read a couple of QPU tutorials, including Herman Hermitage's, in the context of trying to use it for bitcoin mining. That was back about April.

I think he says the graphics are running under OpenGL and he does plan to release the code someday.

Grabbed a couple frames from the video with mplayer -vo jpeg
00000938.jpg
00000938.jpg (13.88 KiB) Viewed 4545 times
00002685.jpg
00002685.jpg (17.36 KiB) Viewed 4545 times

User avatar
PeterO
Posts: 5958
Joined: Sun Jul 22, 2012 4:14 pm

Re: 'undefined reference to 'mbox_open()'

Fri Jul 14, 2017 6:47 am

Yes, I know all about that project :-), now, have you tested your code with a sine wave yet ?
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
ab1jx
Posts: 885
Joined: Thu Sep 26, 2013 1:54 pm
Location: Heath, MA USA
Contact: Website

Re: 'undefined reference to 'mbox_open()'

Fri Jul 14, 2017 11:54 am

Still working on it, I wrote a little program that generated sine waves as ASCII to stdout, thought maybe I should use binary files instead. Or instead of the file reading baggage just generate the sine wave in hello_fft.c. I've been getting everything to work by just sticking code into hello_fft.c and compiling it there. So I load my data with these fgetcs since it's basically unsigned chars. Uh-oh, fgetc reads signed ints. I just realized the signedness could be causing a problem, there are definitely numbers over 127 in there.

Code: Select all

//            for (i=0; i<N; i++) base[i].re = base[i].im = 0;
            for (i=0; i<N; i++) {
              base[i].re = fgetc(ipf);
              base[i].im = fgetc(ipf);
            }
I grabbed my IQ data with a little program that opens a socket to RTL_TCP.
ISTR the last time I looked at this the the GPU FFT was not that much faster that fftw.
PeterO
That might be worth investigating, since when Peter Onion did his panadapter a Pi was single core 700 MHz.

Oh, do I need to simulate the imaginary part, like maybe just zeroes? If an FFT works like I think it does the zeroes will just be a different bin in a different place.

User avatar
PeterO
Posts: 5958
Joined: Sun Jul 22, 2012 4:14 pm

Re: 'undefined reference to 'mbox_open()'

Fri Jul 14, 2017 12:23 pm

ab1jx wrote: That might be worth investigating, since when Peter Onion did his panadapter a Pi was single core 700 MHz.
Penny not dropped yet ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
ab1jx
Posts: 885
Joined: Thu Sep 26, 2013 1:54 pm
Location: Heath, MA USA
Contact: Website

Re: 'undefined reference to 'mbox_open()'

Fri Jul 14, 2017 1:53 pm

Yeah, OK, it was that Santa Claus suit. Still chuckling.

The CPU's speeded up a lot more than the GPU which makes fftw more appealing. Except I like to not hog the CPU under the assumption there may be several tasks running concurrently, so using the GPU pushes some load off onto it. Might also want to be running multimon, fldigi, wxtoimg that does something with the audio once it's demodulated. Efficiency's rarely a bad thing I think. I appreciate Gnuradio for what it can do, but it's so huge and finicky I've rarely had it working and wouldn't think about using it every day.

Back about February I was studying some xlib stuff because I wanted the lowest level way to put pixels on the screen. I can allocate memory, draw into it, save it out with jpeglib, pnglib, giflib, whatever, but no motion. The designed-in versatility of xlib with color maps and planes and depths seems lot a lot of extra baggage, I'm more used to a memory-mapped screen. So it's worthwhile learning OpenGL?

I've had Hdsdr, sdrsharp, etc. around for years but now that I've been retired for 8 years I'm finally digging into how they work inside. I got my extra class ham ticket because I like to play with antennas. I model way more than I actually build. The studying was more interesting than most of the people I met on the air so I haven't been on in years. I'd like to see an hdsdr for unix, gqrx has too much of Gnuradio in it, there's still too much bloat.

User avatar
ab1jx
Posts: 885
Joined: Thu Sep 26, 2013 1:54 pm
Location: Heath, MA USA
Contact: Website

Re: 'undefined reference to 'mbox_open()'

Sat Jul 15, 2017 1:01 am

I've tried several times and it's always come out like this. I don't know why the peak's on the right or why I'm only seeing one of them. This is "plot 'fftout2.txt' using 1:2" so it's an xy plot (I guess).
junk2a.gif
junk2a.gif (7.92 KiB) Viewed 4453 times
This is from "plot 'fftout2.txt' using 1, 'fftout2.txt' using 2 so it's 2 yt plots.
junk2b.gif
junk2b.gif (9.34 KiB) Viewed 4453 times
I also did a square wave and that doesn't look right either.
square1.gif
square1.gif (7.32 KiB) Viewed 4453 times
So, I'm starting over by putting my program in the same directory and makefile.

User avatar
PeterO
Posts: 5958
Joined: Sun Jul 22, 2012 4:14 pm

Re: 'undefined reference to 'mbox_open()'

Sat Jul 15, 2017 7:56 pm

Post your code and I'll give it a whirl and see what's going on.
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
ab1jx
Posts: 885
Joined: Thu Sep 26, 2013 1:54 pm
Location: Heath, MA USA
Contact: Website

Re: 'undefined reference to 'mbox_open()'

Sat Jul 15, 2017 9:21 pm

Well, I'm not quite to that point. I've just been sticking a few lines into /opt/vc/src/hello_pi/hello_fft/hello_fft.c to do what I wanted. I had barely started over when I went to borrow a windowing function from rtl_fm to be sure I was going to be able to accommodate it.

Except there isn't one, and there isn't any obvious fft either, only in rtl_power. So it seems doing an fft, having a pan adapter with waterfall, etc. is superfluous to actually getting audio. I'll probably come back to it later for survey purposes but right now I'm sidetracked trying to make a GTK version of rtl_fm. Just with a frequency display that you can change while it's running, a few basic radio controls. And maybe a knob for tuning or just left and right arrow so you can (blindly) tune through signals. rtl_fm has always been my reference, I was planning to pirate demodulator code from it. Building a small Winamp style interface appeals to me at the moment. I recently looked at piclone source and found it to be a reasonably understandable GTK demo program. Right now I'm trying to get a fresh version of the rtl_sdr suite running under OpenBSD because that's what my main computer in the basement runs. rtl_fm does AM and SSB/CW too, and can do direct or offset tuning so I can take the plunge and do a direct connection or use my upconverter, the W9RAN one from the January 2013 QST. I guess there were 22 different ones as of 2012 https://retrovoltage.com/2012/09/14/rou ... r-choices/

I think I could take an IQ output from rtl_fm, using its interface to the dongle, and do FFT on that to make a waterfall, but turn it off if I just want to listen. I have one dongle receiving thermometer data with rtl_433, I used another to batch record the BBC's Newshour to MP3s once a day. My goal was really to experiment, see how parts fit together.

At first it was hard to take SDR seriously because it meant tying up a computer to do much, but the Raspberry Pi changes that at under 2 watts.

User avatar
ab1jx
Posts: 885
Joined: Thu Sep 26, 2013 1:54 pm
Location: Heath, MA USA
Contact: Website

Re: 'undefined reference to 'mbox_open()'

Wed Jul 19, 2017 5:15 pm

I spent 3 days with no internet but I had the last part of your http://www.peteronion.org.uk/FFT/FastFourier.html page saved as a PDF. Went back to it, got correct sine and square wave plots finally, not sure I still have them.

Wrote a loop that pulls 4096 bytes of IQ data from rtl_tcp, does an fft, saves to a file, does that 10 times and I have to do the gnuplot bit mostly manually. This is from our FM broadcast band so there are plenty of test signals, strong wideband FM 30 KHz apart. It's not quite what I expected it to look like though. I didn't have the windowing part of the article saved. I pirated a DC removal routine from rtl_power but I didn't get the windowing. I'm surprised the baselines look like sine waves 90 degrees apart, for some reason I thought the shift would only apply to the RF waves.
iq5.gif
iq5.gif (20.56 KiB) Viewed 4342 times
Did a cat on the tab-delimited files to string them all together, they came out like this. For some reason the first one is different. rtl_tcp puts out a little header of 20 bytes or so with a dongle ID but that doesn't seem significant.
alliq.gif
alliq.gif (19.06 KiB) Viewed 4333 times
Found my sine and square wave plots (but 3 is the limit).
fft1.gif
fft1.gif (10.99 KiB) Viewed 4328 times
Looking at my plots above of real IQ data compared to the ones in the article above, it looks like I'm seeing a raw envelope as opposed to a rectified (aka detected) halfwave. This same rectification would be done in an RF probe or SWR meter, wherever it's necessary to turn a peak to peak measurement into a peak one. Done in software no doubt. I don't think windowing by itself is going to do it. More like the absolute value of delta Y from one point to the next, and that smooths out the baseline too.

User avatar
ab1jx
Posts: 885
Joined: Thu Sep 26, 2013 1:54 pm
Location: Heath, MA USA
Contact: Website

Re: 'undefined reference to 'mbox_open()'

Wed Jul 19, 2017 9:30 pm

iq4.gif
iq4.gif (15.04 KiB) Viewed 4322 times
I think I'm getting warm. I subtract the value of the last point from the value of the current point, if the difference is < 0 I multiply it by -1.

Still need to do some filtering. And this is a day later, all the stations are still in the same places.
Last edited by ab1jx on Wed Jul 19, 2017 9:55 pm, edited 1 time in total.

User avatar
PeterO
Posts: 5958
Joined: Sun Jul 22, 2012 4:14 pm

Re: 'undefined reference to 'mbox_open()'

Wed Jul 19, 2017 9:40 pm

ab1jx wrote:
iq4.gif
I think I'm getting warm. I subtract the value of the last point from the value of the current point, if the difference is < 0 I multiply it by -1.
Still need to do some filtering.
I have no idea what you are talking about here....
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Return to “C/C++”