Linux Segmentation Fault Error Using Command Line


#1

Hey everyone, for some odd reason, im trying to run a very simple Juce command line program on my raspberry pi. Everything works fine but when I try to get a list of all connected midiInputs I get a “Segmentation Fault” error. Not sure whats going on here, any advice??? Also a snippet of my code is below, thanks

 // MidiOutputDemo.h
#pragma once
#include "../JuceLibraryCode/JuceHeader.h"
#include <iostream>
using namespace std;

class MidiOutputDemo   
{
    public:
        MidiOutputDemo()
{
	    cout <<  MidiInput::getDevices().size();
          //StringArray midiInputs  = MidiInput::getDevices();
	     // cout << midiInputs.size();
}
      ~MidiOutputDemo()
{
}   
private:
     JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MidiOutputDemo)
};

 //main.cpp
  #include "MidiOutputDemo.h"
  int main (int argc, char* argv[])
   {    
        MidiOutputDemo midiOutput;
        return 0;
   }

#2

From looking at your code I can’t imagine how this would cause a segfault, but as you say this is a snippet of your code, is there more code in your project? If yes most probably the error is somewhere else. If it is possible to you, I would build the whole project on a desktop Linux computer with some IDE (I personally prefer CLion on Ubuntu, but it doesn’t come for free unless you are a student) that gives you nice debugging tool. A debugger will stop at the line of code that caused the fault and you can have a look at the call stack to find out which functions were called before that lead to the misbehavior. It is also possible to remotely debug the Pi and do all that without a nice IDE, however this is a quite more sophisticated task.
Otherwise, maybe you want to share the whole code?

One other point that should not be the cause of any runtime error here but that is a general advice in terms of coding style is that it is recommended to not write a using namespace statement in any .h file.
The reason behind that is that each file that includes this header then automatically uses this namespace without making this fact visible to the user when reading the code. If projects get more complex this could have unintended side-effects and generate compile-time errors. Better get used to just write std::cout and so on directly, that makes things a lot clearer when reading the code later on.


#3

thanks, yea will have to configure this on a linux desktop for sure, due to the ease of debugging. I will test this out and see if its giving me the same issues. Also your right about the namespace tip, I totally forgot about that… :slight_smile: