Search code examples
c++xcodejuce

Initializing AudioDeviceManager in JUCE Audio App


I am trying to initialize the instance of AudioDeviceManager, in the constructor of my MainContentComponent:

MainContentComponent(): deviceManager (getSharedAudioDeviceManager())

where

  AudioDeviceManager& getSharedAudioDeviceManager()  
     {  

 if (sharedAudioDeviceManager == nullptr)

    {
        sharedAudioDeviceManager = new AudioDeviceManager();
        sharedAudioDeviceManager->initialise (2, 2, 0, true, String::empty, 0);
    }

    return *sharedAudioDeviceManager;
} 

and my declarations would be:

AudioDeviceManager& deviceManager; static ScopedPointer<AudioDeviceManager> sharedAudioDeviceManager;

There are no compile errors, but I have runtime errors, wherein the compiler tells me:

Undefined symbols for architecture x86_64: "MainContentComponent::sharedAudioDeviceManager", referenced from: MainContentComponent::getSharedAudioDeviceManager() in MainComponent.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Totally lost. Help!


Solution

  • You need to define your static member outside of the class declaration, like this...

    ScopedPointer<AudioDeviceManager> MainContentComponent::sharedAudioDeviceManager;
    

    Also, this is a linktime error, not a runtime error.