1

I’ve successfully built and compiled JUCE on a raspberry pi b+ which works smooth. Now I'm trying to use WiringPi within JUCE with a knob/rotary encoder to display text on a lcd. Everything works but when I try to call wiringPi functions inside my juce app I get “undefined reference errors” to wiringPi.

My question is, how do I build WiringPi and Juce at the same time so that i can call wiringPi methods/functions inside of JUCE. Below is a snippet of my code

Here is the error im getting below:

Source/SynthUsingMidiInputTutorial_01.h:114: undefined reference to `wiringPiSetup'
Source/rotary_encoder.h:40: undefined reference to `digitalRead'
Source/SynthUsingMidiInputTutorial_01.h:122: undefined reference to `pinMode'
Source/SynthUsingMidiInputTutorial_01.h:125: undefined reference to `pullUpDnControl'

Source code:

//SynthUsingMidiInputTutorial_01.h
#include "rotary_encoder.h"

class SynthAudioSource : public AudioSource
{
public:
SynthAudioSource (MidiKeyboardState& keyState)
: keyboardState (keyState)
{
    // add voices to our sampler
    for (int i = 0; i < MAX_VOICES; i++)
    {
        synth.addVoice(new SamplerVoice());
    }

    // set up our AudioFormatManager class as detailed in the API docs
    audioFormatManager.registerBasicFormats();
    // now that we have our manager, lets read a simple file so we can pass it to our SamplerSound object.
    File* file1 = new File("bass.wav");
    ScopedPointer<AudioFormatReader> reader1 = audioFormatManager.createReaderFor(*file1);
    File* file2 = new File("lead.wav");
    ScopedPointer<AudioFormatReader> reader2 = audioFormatManager.createReaderFor(*file2);
    File* file3 = new File("organ.wav");
    ScopedPointer<AudioFormatReader> reader3 = audioFormatManager.createReaderFor(*file3);
    BigInteger notes;

    notes.setRange (0, 1, true);
    SamplerSound::Ptr sound1 = new SamplerSound ("xx1", *reader1, notes, 0, 0.0, 1.0, 10.0);
    synth.addSound (sound1);
    BigInteger notes2;
    notes2.setRange (1, 1, true);
    SamplerSound::Ptr sound2 = new SamplerSound ("xx2", *reader2, notes2, 0, 0.0, 1.0, 10.0);

    synth.addSound (sound2);
    BigInteger notes3;
    notes3.setRange (2, 1, true);
    SamplerSound::Ptr sound3 = new SamplerSound ("xx3", *reader3, notes3, 0, 0.0, 1.0, 10.0);

    synth.addSound (sound3);
    int lcd;                //Handle for LCD
    wiringPiSetup();        //Initialise WiringPi

    //Initialise LCD
    if (lcd = lcdInit (2, 16,4, LCD_RS, LCD_E ,LCD_D4 , LCD_D5, LCD_D6,LCD_D7,0,0,0,0))
    {
        std::cout << "LcdInit failed!:";
    }

    pinMode(SwitchPin, INPUT);
    pinMode(RotateAPin, INPUT);
    pinMode(RotateBPin, INPUT);
    pullUpDnControl(SwitchPin, PUD_UP);

    if (wiringPiISR(SwitchPin, INT_EDGE_FALLING, &btnISR) < 0) 
    {
        cout << "Unable to init ISR" << endl;
    }

    int tmp = 0;
    while (1) 
    {
        rotaryDeal();
        if (tmp != globalCounter) 
        {
            tmp = globalCounter;
            if(globalCounter >= 10)
            break;
        }    
    }

    lcdPosition(lcd,0,0);           //Position cursor on the first line in the first column
    lcdPuts(lcd, "Lead Bass:");  //Print the text on the LCD at the current cursor postion
}

And:

//rotary_encoder.h
#include <wiringPi>

static volatile int globalCounter = 0;
unsigned char flag;
unsigned char Last_RoB_Status;
unsigned char Current_RoB_Status;

void btnISR(void) 
{
    globalCounter = 0;
}

void rotaryDeal() 
{
    Last_RoB_Status = digitalRead(RotateBPin);
    while (!digitalRead(RotateAPin))
    {
        Current_RoB_Status = digitalRead(RotateBPin);
        flag = 1;
    }
    if (flag == 1)
    {
        flag = 0;
        if ((Last_RoB_Status == 0) && (Current_RoB_Status == 1)) 
        {
            globalCounter++;
        }
        if ((Last_RoB_Status == 1) && (Current_RoB_Status == 0)) {
            globalCounter--;
        }
    }
}
jww
  • 97,681
  • 90
  • 411
  • 885
T Shoats
  • 347
  • 2
  • 4
  • 19
  • 1
    Please show your compile and link command. It appears you are missing a link library or link objects are in the wrong order. Also see [Why does the order in which libraries are linked sometimes cause errors in GCC?](https://stackoverflow.com/q/45135/608639) and more generally [g++ linker does order matter](https://duckduckgo.com/?q=g%2B%2B+linker+does+order+matter) – jww Jan 28 '19 at 03:18
  • thanks @jww ,I actually found the problem. It was just as you suggested. – T Shoats Jan 28 '19 at 03:35
  • thank you @jww for the help, i totally forgot about the blocks etc – T Shoats Jan 28 '19 at 23:16

0 Answers0