Hello world with Xcode?


#1

Hey everyone! I am almost a complete newbie in programming. Took some classes in C/C++ programming but never written anything with GUI so now decided to try Juce.

Could anyone write a step by step instructions on how to configure Xcode to work with juce and then how to write a basic application that shows a window with text “Hello World”?

Thanks a lot in advance!


#2

look at:

juce/extras/example projects/example_project_for_Mac/

and see:

http://www.rawmaterialsoftware.com/juceforum/viewtopic.php?t=1935


#3

Thanks, I just found this topic myself, but it does not give step by step instructions for Xcode.


#4

You can create a Carbon project, remove main.c/main.cpp from your project and add the files posted by haydxn.


#5

This does not work for me (errors at the linking stage). Maybe because I’m on OSX 10.6.2 with XCode 3.2.1.
Some more details: There are still these AppDelegate.* files around, and when viewing the Properties of the Target I see that it has the principal class NSApplication, which I think is a Cocoa class (I’m a newbie and my acting at this stage is based on guesswork). Why is it not working? I don’t have a clue (about XCode).

One question bothers me: How does XCode figure out on which file the whole process should start, i.e. does it always start with main.cpp? What does it pick if there is no main.cpp? I’m quite sure one can define this property somewhere.
Sorry that I haven’t dived more into the XCode documentation and figured this out by myself, but the documentation starts quite early with Cocoa coding, and, well, you know, I would like to learn Juce instead of Cocoa. Or is there some big benefit to first dive into Cocoa?

Anyhow, here is my step by step guide, for other beginners like me

  1. Make sure your extras/example projects works. If not, take a look at http://www.rawmaterialsoftware.com/viewtopic.php?f=4&t=5049

  2. Make a copy of this “example projects” folder and open the XCode-Project inside.

  3. Via File/New File… -> “C++ File” or “Header File” generate the four files as described in http://www.rawmaterialsoftware.com/viewtopic.php?f=2&t=1935 .

  4. Delete all source files except these four and the juce_LibrarySource.mm

  5. Make sure the path to juce.h (or juce_amalgamated.h) is correct in the file MainAppWindow.h as well as in MainComponent.h. In my case, it’s
    #include "…/…/…/juce_amalgamated.h"
    i.e. with an additional “…/”

  6. Build and run.

You’re ready for haydxn’s tutorial! http://code.google.com/p/juced/wiki/JuceTutorial


#6

You get linker errors because you are not linking against the frameworks required by juce.

Add the frameworks used by juce demo to your project.


#7

Thank you for your reply.

I did drag and drop the juce.xcodeproj to the “Other Frameworks” and from there the libjuce.a to the “Target//Link Binary with Libraries”. As described in the readme. Most of the errors look like this: “juce::Component::… referend from:”. Do I also need to add some more Apple Frameworks, as mentioned in the readme? I assumed not, since this is such a basic application.

Instead of “libjuce.a” and “libjucedebug.a” there are two “libjuce.a” listed under “juce.xcodeproj”. I dragged only one of them to the “Link Binary with Libraries” and tried to build in debug and in release mode, since I couldn’t know to which it belongs. Both raises linking errors, one more than the other. (In the juce/bin/UninstalledProducts folder on my harddrive, there are these two files “libjuce.a” and “libjucedebug.a”)


#8

[quote=“samuel”]Thank you for your reply.

I did drag and drop the juce.xcodeproj to the “Other Frameworks” and from there the libjuce.a to the “Target//Link Binary with Libraries”. As described in the readme. Most of the errors look like this: “juce::Component::… referend from:”. Do I also need to add some more Apple Frameworks, as mentioned in the readme? I assumed not, since this is such a basic application.

Instead of “libjuce.a” and “libjucedebug.a” there are two “libjuce.a” listed under “juce.xcodeproj”. I dragged only one of them to the “Link Binary with Libraries” and tried to build in debug and in release mode, since I couldn’t know to which it belongs. Both raises linking errors, one more than the other. (In the juce/bin/UninstalledProducts folder on my harddrive, there are these two files “libjuce.a” and “libjucedebug.a”)[/quote]

Don’t drag the juce.xcodeproj to your application’s xcode project, rather drag and drop libjuce.a(release library for release build) or libjucedebug.a(debug library for debug build).

You would have to add Apple Frameworks since juce uses it. To avoid adding these frameworks you would have to unset few macros. (You should find them in juce readme).

Can you post few of the linker errors you have faced?


#9

[quote=“vishvesh”]
Don’t drag the juce.xcodeproj to your application’s xcode project, rather drag and drop libjuce.a(release library for release build) or libjucedebug.a(debug library for debug build).

You would have to add Apple Frameworks since juce uses it. To avoid adding these frameworks you would have to unset few macros. (You should find them in juce readme).

Can you post few of the linker errors you have faced?[/quote]

I added the libjuce.a like you suggested and I also added all Apple Frameworks listed in Jules readme. I have chosen the same SDK (OSX 10.6) and the same architecture (i386) as was selected in the juce.xcodeproj e.g. the settings the libjuce.a was built for.

Here are the errors for the first file:

ld: warning: in /Users/sam/data/res/projects_dev/juce100209/juce/bin/UninstalledProducts/libjuce.a, file is not of required architecture ld: warning: in /System/Library/Frameworks//QuickTime.framework/QuickTime, missing required architecture x86_64 in file Undefined symbols: "juce::JUCEApplication::~JUCEApplication()", referenced from: AppClass::~AppClass()in ApplicationStartup.o AppClass::~AppClass()in ApplicationStartup.o "juce::Component::centreWithSize(int, int)", referenced from: AppClass::initialise(juce::String const&) in ApplicationStartup.o "juce::DocumentWindow::activeWindowStatusChanged()", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::Component::canModalEventBeSentToComponent(juce::Component const*)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::Component::mouseDown(juce::MouseEvent const&)", referenced from: vtable for MainComponentin MainAppWindow.o "juce::ResizableWindow::childBoundsChanged(juce::Component*)", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::JUCEApplication::getNextCommandTarget()", referenced from: vtable for AppClassin ApplicationStartup.o "juce::String::String(wchar_t const*)", referenced from: AppClass::getApplicationVersion() in ApplicationStartup.o AppClass::getApplicationName() in ApplicationStartup.o MainAppWindow::MainAppWindow()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o "juce::Component::addToDesktop(int, void*)", referenced from: vtable for MainComponentin MainAppWindow.o "juce::DocumentWindow::~DocumentWindow()", referenced from: MainAppWindow::~MainAppWindow()in MainAppWindow.o MainAppWindow::~MainAppWindow()in MainAppWindow.o MainAppWindow::MainAppWindow()in MainAppWindow.o "juce::Component::mouseDrag(juce::MouseEvent const&)", referenced from: vtable for MainComponentin MainAppWindow.o "juce::Component::internalRepaint(int, int, int, int)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::Component::inputAttemptWhenModal()", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::Component::handleCommandMessage(int)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::Component::~Component()", referenced from: MainComponent::MainComponent()in MainAppWindow.o MainComponent::~MainComponent()in MainAppWindow.o MainComponent::~MainComponent()in MainAppWindow.o MainComponent::~MainComponent()in MainAppWindow.o MainComponent::~MainComponent()in MainAppWindow.o "juce::DocumentWindow::getContentComponentBorder()", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::Component::moved()", referenced from: vtable for MainComponentin MainAppWindow.o "juce::DocumentWindow::mouseDoubleClick(juce::MouseEvent const&)", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::Component::mouseEnter(juce::MouseEvent const&)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "non-virtual thunk to juce::JUCEApplication::actionListenerCallback(juce::String const&)", referenced from: vtable for AppClassin ApplicationStartup.o "juce::Component::mouseDoubleClick(juce::MouseEvent const&)", referenced from: vtable for MainComponentin MainAppWindow.o "juce::DocumentWindow::maximiseButtonPressed()", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::ResizableWindow::parentSizeChanged()", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::TopLevelWindow::addToDesktop(int, void*)", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::String::~String()", referenced from: MainAppWindow::MainAppWindow()in MainAppWindow.o MainAppWindow::MainAppWindow()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o "juce::JUCEApplication::getAllCommands(juce::Array<int, juce::DummyCriticalSection>&)", referenced from: vtable for AppClassin ApplicationStartup.o "typeinfo for juce::Component", referenced from: typeinfo for MainComponentin MainAppWindow.o "juce::Colours::azure", referenced from: MainAppWindow::MainAppWindow()in MainAppWindow.o "juce::Component::paintOverChildren(juce::Graphics&)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::ResizableWindow::mouseDown(juce::MouseEvent const&)", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::JUCEApplication::actionListenerCallback(juce::String const&)", referenced from: vtable for AppClassin ApplicationStartup.o "juce::Component::parentSizeChanged()", referenced from: vtable for MainComponentin MainAppWindow.o "juce::Component::setName(juce::String const&)", referenced from: vtable for MainComponentin MainAppWindow.o "juce::Slider::Slider(juce::String const&)", referenced from: MainComponent::MainComponent()in MainAppWindow.o "juce::JUCEApplication::getInstance()", referenced from: MainAppWindow::closeButtonPressed() in MainAppWindow.o "juce::Component::setBounds(int, int, int, int)", referenced from: MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o "juce::JUCEApplication::JUCEApplication()", referenced from: _main in ApplicationStartup.o "juce::DocumentWindow::setTitleBarHeight(int)", referenced from: MainAppWindow::MainAppWindow()in MainAppWindow.o "juce::DocumentWindow::parentHierarchyChanged()", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::DocumentWindow::userTriedToCloseWindow()", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::ResizableWindow::mouseDrag(juce::MouseEvent const&)", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::Component::broughtToFront()", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::JUCEApplication::unhandledException(std::exception const*, juce::String const&, int)", referenced from: vtable for AppClassin ApplicationStartup.o "juce::Label::Label(juce::String const&, juce::String const&)", referenced from: MainComponent::MainComponent()in MainAppWindow.o "juce::TooltipWindow::~TooltipWindow()", referenced from: MainComponent::MainComponent()in MainAppWindow.o MainComponent::~MainComponent()in MainAppWindow.o MainComponent::~MainComponent()in MainAppWindow.o MainComponent::~MainComponent()in MainAppWindow.o MainComponent::~MainComponent()in MainAppWindow.o "juce::Component::addAndMakeVisible(juce::Component*, int)", referenced from: MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o "juce::Component::mouseMove(juce::MouseEvent const&)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::Component::mouseExit(juce::MouseEvent const&)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::Component::lookAndFeelChanged()", referenced from: vtable for MainComponentin MainAppWindow.o "juce::JUCEApplication::perform(juce::ApplicationCommandTarget::InvocationInfo const&)", referenced from: vtable for AppClassin ApplicationStartup.o "juce::Component::Component()", referenced from: MainComponent::MainComponent()in MainAppWindow.o "juce::Component::mouseWheelMove(juce::MouseEvent const&, float, float)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::Component::childrenChanged()", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::Component::setVisible(bool)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::Component::modifierKeysChanged(juce::ModifierKeys const&)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::Component::focusOfChildComponentChanged(juce::Component::FocusChangeType)", referenced from: vtable for MainComponentin MainAppWindow.o "juce::Component::childBoundsChanged(juce::Component*)", referenced from: vtable for MainComponentin MainAppWindow.o "juce::Component::keyPressed(juce::KeyPress const&)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::DocumentWindow::minimiseButtonPressed()", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::Component::parentHierarchyChanged()", referenced from: vtable for MainComponentin MainAppWindow.o "juce::Component::userTriedToCloseWindow()", referenced from: vtable for MainComponentin MainAppWindow.o "juce::TopLevelWindow::focusOfChildComponentChanged(juce::Component::FocusChangeType)", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::Component::minimisationStateChanged(bool)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::JUCEApplication::systemRequestedQuit()", referenced from: vtable for AppClassin ApplicationStartup.o "juce::DocumentWindow::resized()", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::Component::keyStateChanged(bool)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::TextButton::TextButton(juce::String const&, juce::String const&)", referenced from: MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o MainComponent::MainComponent()in MainAppWindow.o "juce::ResizableWindow::setContentComponent(juce::Component*, bool, bool)", referenced from: MainAppWindow::MainAppWindow()in MainAppWindow.o "juce::DocumentWindow::setName(juce::String const&)", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::ResizableWindow::setResizable(bool, bool)", referenced from: MainAppWindow::MainAppWindow()in MainAppWindow.o "juce::ResizableWindow::moved()", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::Component::mouseUp(juce::MouseEvent const&)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::DocumentWindow::paint(juce::Graphics&)", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::TooltipWindow::TooltipWindow(juce::Component*, int)", referenced from: MainComponent::MainComponent()in MainAppWindow.o "juce::String::empty", referenced from: MainComponent::MainComponent()in MainAppWindow.o "juce::Component::enablementChanged()", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::Component::handleMessage(juce::Message const&)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::Component::focusGained(juce::Component::FocusChangeType)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "non-virtual thunk to juce::Component::handleMessage(juce::Message const&)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::DocumentWindow::getBorderThickness()", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::Component::createNewPeer(int, void*)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::Component::deleteAllChildren()", referenced from: MainComponent::~MainComponent()in MainAppWindow.o MainComponent::~MainComponent()in MainAppWindow.o "juce::DocumentWindow::DocumentWindow(juce::String const&, juce::Colour const&, int, bool)", referenced from: MainAppWindow::MainAppWindow()in MainAppWindow.o "typeinfo for juce::DocumentWindow", referenced from: typeinfo for MainAppWindowin MainAppWindow.o "juce::JUCEApplication::main(int, char**, juce::JUCEApplication*)", referenced from: _main in ApplicationStartup.o "juce::DocumentWindow::lookAndFeelChanged()", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::ResizableWindow::visibilityChanged()", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::JUCEApplication::getCommandInfo(int, juce::ApplicationCommandInfo&)", referenced from: vtable for AppClassin ApplicationStartup.o "typeinfo for juce::JUCEApplication", referenced from: typeinfo for AppClassin ApplicationStartup.o "juce::Component::getMouseCursor()", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::Component::contains(int, int)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::Component::focusLost(juce::Component::FocusChangeType)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::Component::createFocusTraverser()", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::DocumentWindow::getDesktopWindowStyleFlags() const", referenced from: vtable for MainAppWindowin MainAppWindow.o "juce::Component::hitTest(int, int)", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o "juce::Component::visibilityChanged()", referenced from: vtable for MainComponentin MainAppWindow.o "juce::Component::colourChanged()", referenced from: vtable for MainAppWindowin MainAppWindow.o vtable for MainComponentin MainAppWindow.o ld: symbol(s) not found collect2: ld returned 1 exit status

I also built libjuce.a for the SDK 10.5 and also tried to build my project with this SDK, but the same errors occured.

I really appreciate your help! I also would like to let you know that for me it’s not very important to make this work (at the moment). I have a project that builds and which I can use as a starting point. Maybe in a couple of months I will have the knowledge to figure it out myself.
But if YOU would like to go one, I’m happy to follow your suggestions.


#10

U have not built the juce library for ur architecture. Create a universal library so that it will work on all the machines. That might be one problem Though its just a warning.

Other thing i can think is the library is not been added to the target properly.


#11

Thank you, this was it (I had to select the same architecture in the info panel, doing it in the pop up list on the top left wasn’t enough). Now it builds just fine.


#12

@Godwin
Hey Godwin, He is working on snow leopard, so universal library would be (32 bit and 64 bit).

@samuel
From the error it looks like you had built juce library for 32 bit. This was the clue.


#13

@ vishvesh
To build the libjuce.a I had to switch from the “$(NATIVE_ARCH)” architecture (Juce.xcodeproj comes with this) to “Standard (32/64 bit Universal)”.

I work with a Macbook2,1 Intel Core 2 Duo and in the System Profiler/Software it says: 64-bit Kernel and Extensions: No.
But I’m aware that 10.6.2 can execute 32bit and 64bit code.


#14

@vishvesh.
Yeah it should build in all the architectures.


#15

One additional note:
The libjuce.a builds fine for the “Standard (32/64 bit Universal)” architecture, but not the libjucedebug.a. No mather which SDK I choose (10.5 or 10.6) or which architecture in the popup (x86_64 or i386) is selected, the following error occures:

<built-in>:0: warning: Mac OS X version 10.5 or later is needed for use of the new objc abi In file included from /Users/sam/data/res/projects_dev/juce100209/juce/build/macosx/../../src/native/juce_mac_NativeCode.mm:122: /Users/sam/data/res/projects_dev/juce100209/juce/build/macosx/../../src/native/mac/juce_mac_MessageManager.mm: In member function 'void juce::MessageManager::runDispatchLoop()': /Users/sam/data/res/projects_dev/juce100209/juce/build/macosx/../../src/native/mac/juce_mac_MessageManager.mm:303: error: Mac OS X version 10.5 or later is needed for zerocost-exceptions

For the architecture “32-bit Universal”, libjucedebug.a builds successfully.