Thanks to the Projucer, I created this very basic project, just to understand how to generate a static library for iOS and how to import it on an iOS project.
I managed to generate the library and locate the .a file. By running lipo -info libJuceDemo.a , I can see that it’s a non fat file, targeting the arm64 architecture.
Now I’m trying to import it on an iOS project, and here is what I did:
I created a CPP group, then a Juce group, and copied all the necessary files init it, as you can see here:
If I go to Runner > Targets > General > Frameworks, Libraries, and Embedded Content , I can see that libJuceDemo.a is here, as expected
Then I went to Runner > Project > Build Settings > Search Paths , and for Header Search Paths , I added $SRCROOT/Runner/CPP/Juce and $SRCROOT/../../../../JUCE/modules (where is JUCE installed, basically)
Now when I try to compile and run my iOS app, I get a very long error message, that ends with:
symbol(s) not found for architecture arm64
And I have a whole bunch of error like this:
Undefined symbols for architecture arm64:
"_MIDIOutputPortCreate", referenced from:
juce::AudioDeviceManager::setDefaultMidiOutputDevice(juce::String const&) in Runner_lto.o
even though I build my library targeting the arm64 architecture…
You need to link to the relevant frameworks in your parent project when adding a static library.
You can search for the missing function names in the Apple docs, that is one way to find the associated framework. Below is a list of the frameworks I think JUCE currently relies on (I don’t currently have access to relevant projects to confirm, corrections welcome!)
CoreAudio
AudioToolbox
CoreFoundation
Foundation
accelerate
CoreMIDI
CoreServices
CoreGraphics
libc++.tbd
Let’s take the CoreAudio framework for example, how to add it in my parent project?
I haven’t managed yet to find any documentation on that.
Also, I went to Targets > Build Phases > Link Binary With Libraries, clicked on the + button, search for CoreAudio.framework, added it, but nothing changed…
OK so I have one last error, that I don’t understand:
Undefined symbols for architecture arm64:
"juce::this_will_fail_to_link_if_some_of_your_compile_units_are_built_in_debug_mode::this_will_fail_to_link_if_some_of_your_compile_units_are_built_in_debug_mode()", referenced from:
__GLOBAL__sub_I_NativeLib.cpp in NativeLib.o
ld: symbol(s) not found for architecture arm64
Which is weird since I built my library in release mode…
OK but I still don’t get it: in the JUCE source code, I can read: “if you have two cpp files, and one includes the juce headers with debug enabled, and another does so without that, …”
What does “includes the juce headers with debug enabled” mean?
Does it have something to do with the #ifndef instruction?