Building on OSX


#1

A problem with Objective-C headers when compiling C++ JUCE application on OSX 10.10.5, XCode 6.4, QtCreator 3.5 on Macbook Pro.

I am transferring to OSX a C++ application that uses JUCE and which builds and runs fine on Windows 7. I am using Qt Creator as the IDE for building the files. The juce modules I need are being compiled in situ, e.g. the file include_juce_audio_basics.cpp which does #include "../../juce/modules/juce_audio_basics/juce_audio_basics.cpp". My own (generic) code builds fine, but when the compiler hits the juce modules it tries to include NSObjCRuntime.h. which I believe is an Objective C module which is not fully compilable with the c++ compiler and I get syntax errors. I read that such inclusions can be avoided with #ifdef __OBJC__  ... #endif, but where woudl I put these conditional compilation directives and is this the correct solution?

 

 


#2

You shouldn't be including the juce_audio_basics.cpp. On Mac you need to include juce_audio_basics.mm. You need to do the same with any other modules which have .mm file in the modue folder. The file suffix will tell the compiler to expect Obj-C.


#3

Fabian,

Many thanks for your reply. I now include the mm files directly in the QtCreator project file, like so:

OBJECTIVE_SOURCES += ../../../../../juce/modules/juce_audio_basics/juce_audio_basics.mm \ ../../../../../juce/modules/juce_audio_devices/juce_audio_devices.mm \ ../../../../../juce/modules/juce_core/juce_core.mm \ ../../../../../juce/modules/juce_data_structures/juce_data_structures.mm \ ../../../../../juce/modules/juce_events/juce_events.mm \ ../../../../../juce/modules/juce_graphics/juce_graphics.mm \ ../../../../../juce/modules/juce_gui_basics/juce_gui_basics.mm \ ../../../../../juce/modules/juce_gui_extra/juce_gui_extra.mm \ ../../../../../juce/modules/juce_video/juce_video.mm

(Except that the backslashes are each followed by a new line - it doesn't format well in this post)

This solves the compilation errors, but now I get link errors, e.g. "undefined symbol _AudioDeviceCreateIOProcID".  Yes, I know these errors are due to OSX libraries that need to be linked and that I need to add to the LIBS section of my project file, but do you have any advice for the best way to find the names of the OSX libraries corresponding to each missing symbol?

P.S. In case readers are wondering why I am using QtCreator to build a JUCE project, it is because QtCreator has a good debugger, which I like using.

Regards,

Sahlan

 

 

 


#4

To use Qt Creator to build C++ files with JUCE and link to the OSX frameworks, a QtCreator .pro file needs to be formatted as below. I found out how to do this after a lot of searching on the web. Of course, the detail of directory paths and which juce modules you wish to include will be specific to your project.  If you get link errors, then Google the missing symbol (without the underscore prefix) and look at the OSX help page. It will usually have a #import statement on the right hand side, telling you the name of the framework required. Please note the \ symbols that mark line ends. They have not formatted properly in ths post.

TARGET = <app name>

TEMPLATE = app

CONFIG += debug

DEFINES += UNICODE _UNICODE OSX _DEBUG DEBUG JUCER_VS2005_78A5003 JUCE_USE_CAMERA JUCE_QUICKTIME

QMAKE_LFLAGS += -F/System/Library/Frameworks/

LIBS += <list of paths to any special libs you wish to link with> -framework CoreAudio \ -framework AudioToolbox \ -framework CoreFoundation \ -framework Foundation \ -framework CoreText \ -framework CoreVideo \ -framework IOKit \ -framework AppKit \ -framework accelerate \ -framework CoreMIDI \ -framework QTKit \ -framework QuartzCore \ -framework WebKit \ -framework CoreServices \ -framework CoreGraphics

INCLUDEPATH += < list of include paths >

OBJECTIVE_SOURCES += ../../../../../juce/modules/juce_audio_basics/juce_audio_basics.mm \ ../../../../../juce/modules/juce_audio_devices/juce_audio_devices.mm \ ../../../../../juce/modules/juce_core/juce_core.mm \ ../../../../../juce/modules/juce_data_structures/juce_data_structures.mm \ ../../../../../juce/modules/juce_events/juce_events.mm \ ../../../../../juce/modules/juce_graphics/juce_graphics.mm \ ../../../../../juce/modules/juce_gui_basics/juce_gui_basics.mm \ ../../../../../juce/modules/juce_gui_extra/juce_gui_extra.mm \ ../../../../../juce/modules/juce_video/juce_video.mm

SOURCES += < list of your cpp sources >

HEADERS += < list of your h files >

DESTDIR = < output directory for built app >

I am putting this info here for anyone who wishes to try this approach and who does not want to spend a day, as I did, finding out how to do it,

Sahlan