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

Differentiate RPi from other SBCs using compiler flags/etc

Wed Apr 13, 2016 6:43 am

Hi,

I'm developing a program using Andrew Holme's GPU_FFT (which uses the Pi's GPU to speed up FFT), but it must also run on other OSes. Currently my code looks like this:

Code: Select all

FFT* FFT::getInstance() {
    if (!instance.get()) {
#if defined(__linux__)
        instance.reset(new RPiGPU_FFT);
#else
        instance.reset(new KissFFT);
#endif
    }
    return instance.get();
}
Where it will return a pointer from the FFT class's unique_ptr. On Linux this is an instance of RPiGPU_FFT (which is a wrapper class around GPU_FFT's C code) and on any other OS this is an instance of KissFFT, which is a general FFT library.

The issue is, if I compile this for a Linux computer that is not the Raspberry Pi it will fail to run. Does anyone know a way to differentiate between a RPi machine and a non-RPi machine? I'm using QMake as my make system currently, in conjuction with GCC.

jahboater
Posts: 5775
Joined: Wed Feb 04, 2015 6:38 pm
Location: West Dorset

Re: Differentiate RPi from other SBCs using compiler flags/e

Thu Apr 14, 2016 7:40 am

This file, if it exists, contains a nul terminated string starting with Raspberry Pi.

Code: Select all

/sys/firmware/devicetree/base/model
Pi4 8GB running PIOS64

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

Re: Differentiate RPi from other SBCs using compiler flags/e

Mon Apr 18, 2016 11:16 am

jahboater wrote:This file, if it exists, contains a nul terminated string starting with Raspberry Pi.

Code: Select all

/sys/firmware/devicetree/base/model
That's very helpful! Thanks!

Return to “C/C++”