[newbie] Using JUCE with existing code

Discussion and support for general JUCE issues

[newbie] Using JUCE with existing code

Postby chickeneps » Mon Aug 06, 2012 3:10 pm

Newbie question, I know this is likely obvious… I want to use JUCE in my present application to use its audio functions. It says on the intro:

Adding JUCE to your app is very simple - the easiest way involves simply including juce.h in your files and adding a single cpp file to your project. No need to compile any libraries or worry about dependencies.


So I downloaded JUCE, and now I have a folder called "juce". I put the juce folder's path in my projects XCode Header Search paths. I took one of my header files and wrote #include <juce.h>. Then, in that headers accompanying .cpp file, I put a function called TestJUCE(), also declared it in the .h file, and wrote this:

void TestJUCE()
{
OggVorbisAudioFormat* ogg = new OggVorbisAudioFormat();
bool rtBool = ogg->canDoStereo();
}

Upon compiling and linking, I get a link error, Symbol not found.

I've kept this real simple because I just was following the above intro instruction. What am I doing incorrectly?
chickeneps
JUCE Weenie
 
Posts: 7
Joined: Mon Aug 06, 2012 3:07 pm

Re: [newbie] Using JUCE with existing code

Postby jules » Mon Aug 06, 2012 3:26 pm

Sorry, that text is way out of date and I must update it... (Although to be fair you've mis-read it anyway: when it says "add a single CPP file", it doesn't mean *your* cpp file, it means the one with all the juce code in it, hence your link error)

But ignore all that anyway: instead if you're a noob, it's best to just download the introjucer, and use its wizard to create yourself a starter project.
User avatar
jules
Fearless Leader
 
Posts: 17372
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: [newbie] Using JUCE with existing code

Postby chickeneps » Mon Aug 06, 2012 5:55 pm

Thanks for your quick reply.

Actually I was going to ask (just forgot) about "what is that single cpp file you are referring to?" - and I'd still like to know which one it is. The only candidate I would think is "juce_amalgamated.cpp".

Plus I'm further confused - I'm trying to use JUCE with a project that already exists, so checking out the introjucer seems like the long way around. I did open the IntroJucer and tried to figure it out, but it really seems more concerned about laying the basis for a JUCE app from scratch. I'm not trying to do that, I'm trying to use JUCE's audio library functions with a project that already exists.
chickeneps
JUCE Weenie
 
Posts: 7
Joined: Mon Aug 06, 2012 3:07 pm

Re: [newbie] Using JUCE with existing code

Postby TheVinn » Mon Aug 06, 2012 6:02 pm

chickeneps wrote:I'm trying to use JUCE's audio library functions with a project that already exists.


Add juce_core.cpp, juce_audio_basics.cpp, juce_audio_devices.cpp to your existing project. If you need more add the appropriate module .cpp files (like juce_audio_formats.cpp for example).
Open Source: LayerEffects, VFLib, SimpleDJ, DSP Filters, LuaBridge, JUCE, FreeType, TagLib
"This isn't a big project, it shouldn't take long." - Jules
User avatar
TheVinn
JUCE UberWeenie
 
Posts: 2989
Joined: Sat Aug 29, 2009 11:31 am
Location: Marina del Rey, California

Re: [newbie] Using JUCE with existing code

Postby jules » Mon Aug 06, 2012 6:08 pm

You can also still use the juce_amalgamated.h/juce_amalgamated.cpp files too, which just pulls in all the module code.
User avatar
jules
Fearless Leader
 
Posts: 17372
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: [newbie] Using JUCE with existing code

Postby Bruce Wheaton » Mon Aug 06, 2012 6:11 pm

But also, if you use IntroJucer to make a project, you'll have a nice example to copy from. That's the way I've worked with every single framework I've used - get a sample or donor project going to copy from. The exercise of building up the right settings from scratch always seemed disproportionately frustrating. Why not take a shortcut and get to the fun stuff?

Bruce
User avatar
Bruce Wheaton
JUCE UberWeenie
 
Posts: 950
Joined: Thu Aug 17, 2006 1:43 am
Location: Northern California

Re: [newbie] Using JUCE with existing code

Postby chickeneps » Mon Aug 06, 2012 6:31 pm

I tried using Introjucer as an app, I still get the symbol not found stuff.
chickeneps
JUCE Weenie
 
Posts: 7
Joined: Mon Aug 06, 2012 3:07 pm

Re: [newbie] Using JUCE with existing code

Postby jules » Mon Aug 06, 2012 6:36 pm

Thanks, I did already update that stuff on the website. And the introjucer is an app, you can download the binary from sourceforge. Maybe that wasn't clear..
User avatar
jules
Fearless Leader
 
Posts: 17372
Joined: Mon Sep 06, 2004 9:03 am
Location: London, UK

Re: [newbie] Using JUCE with existing code

Postby chickeneps » Mon Aug 06, 2012 6:48 pm

Thanks everyone, I'm still short of the goal...

TheVinn: I shouldn't have to include cpp files to my project, should I? I'm used to just coding .h files in, and it's their responsibility to "go get" the cpp files. It declutters the project area in XCode tremendously, since I"m never going to edit those cpp files anyway.

Please see what I'm doing - I'm simply try to call some incidental function in AudioDataFormat and if my project links, I know I've "connected' with JUCE. I've done this:

#include "juce_core/juce_core.h"
#include "juce_audio_formats/juce_audio_formats.h"

I looked and the OggVorbisAudioFormat objet I'm trying to access is definitely in juce_audio_formats.h. Yet I still get the symbol not found error. I inserted

#define JUCE_USE_OGGVORBIS 1

And that didn't help either.
chickeneps
JUCE Weenie
 
Posts: 7
Joined: Mon Aug 06, 2012 3:07 pm

Re: [newbie] Using JUCE with existing code

Postby TheVinn » Mon Aug 06, 2012 6:50 pm

chickeneps wrote:TheVinn: I shouldn't have to include cpp files to my project, should I?


You need to add those .cpp or else you won't be able to link.
Open Source: LayerEffects, VFLib, SimpleDJ, DSP Filters, LuaBridge, JUCE, FreeType, TagLib
"This isn't a big project, it shouldn't take long." - Jules
User avatar
TheVinn
JUCE UberWeenie
 
Posts: 2989
Joined: Sat Aug 29, 2009 11:31 am
Location: Marina del Rey, California

Re: [newbie] Using JUCE with existing code

Postby Bruce Wheaton » Mon Aug 06, 2012 7:05 pm

chickeneps wrote:TheVinn: I shouldn't have to include cpp files to my project, should I? I'm used to just coding .h files in, and it's their responsibility to "go get" the cpp files. It declutters the project area in XCode tremendously, since I"m never going to edit those cpp files anyway.

Please see what I'm doing - I'm simply try to call some incidental function in AudioDataFormat and if my project links, I know I've "connected' with JUCE


You probably need to revisit what's going on in a C/C++ compiler. The .h files generally only have a definition of what functions are available to you. Then your app also needs to 'link' to those actual functions. Some you will get semi-automatically from the OS. Some will be linked in libraries, either statically or dynamically, and some will be defined in your code, generally in .cpp files.

.h files don't go and do any linking for you, generally. There are some systems like .hpp files, which is basically a .h and .cpp file wrapped into one.

Like I say, download IntroJucer (binary) and get a smaple app compiling on your machine and IDE chain. Then copy the pieces you need to your other app.
Bruce
User avatar
Bruce Wheaton
JUCE UberWeenie
 
Posts: 950
Joined: Thu Aug 17, 2006 1:43 am
Location: Northern California

Re: [newbie] Using JUCE with existing code

Postby chickeneps » Mon Aug 06, 2012 8:02 pm

OK, thank you, I understand I have to include the cpp files. I have been used to using .h files to link up with .lib/.a files of late and got confused. Thank you Bruce for your advice as well. (Boy, do I feel nooby)

OK, so I started up the IntroJucer. Remember, I already have a dylib project I want to use JUCE with. Is the task for me to make some type of faux pas IntroJucer project that has OggVorbisAudioFormat in it, get it to run, the copy-paste that code to my existing project?

What I didn't understand about IntroJucer is that the Open In XCode buttons are grayed out, so I'm not really sure what to do with this. Also, the Tools things - I'm not sure what they completely have to do with IntroJucer. I already have Juce 2.0 in a folder on my computer.

I really thank you for your help.
chickeneps
JUCE Weenie
 
Posts: 7
Joined: Mon Aug 06, 2012 3:07 pm

Re: [newbie] Using JUCE with existing code

Postby Bruce Wheaton » Mon Aug 06, 2012 8:41 pm

chickeneps wrote:Remember, I already have a dylib project I want to use JUCE with. Is the task for me to make some type of faux pas IntroJucer project that has OggVorbisAudioFormat in it, get it to run, the copy-paste that code to my existing project?


Ah, so you have a library you want to use?

Well, yes, anyway. Make a new IntroJucer project. It should have a few 'export targets', including Xcode. Make sure you set your local Juce folder, if it's not the default.

I suggest you start with something super dumb - just a blank window.

Then generate a project, try to compile, link and run it.

Then start adding your custom stuff, ending with adding in your specific libraries.

Bruce
User avatar
Bruce Wheaton
JUCE UberWeenie
 
Posts: 950
Joined: Thu Aug 17, 2006 1:43 am
Location: Northern California

Re: [newbie] Using JUCE with existing code

Postby chickeneps » Mon Aug 06, 2012 9:32 pm

How do you create an "export target" in the Introjucer? I don't see any place where that's an option. All I see is the ability to add .cpp's and .h to the tree, 6 fields for Project Settings, and a Modules area that I'm not sure what relevance it has. The Open in XCode buttons and menus are always grayed out.

I looked around for Introjucer documentation (I really am trying) and I got this:

wiki/index.php/Features#The_Jucer

it says 'A set of wizards make it easy to create application or plugin projects." Where are they? I really don't have any idea. I'm sorry for sounding so elementary, but I'm really trying...
chickeneps
JUCE Weenie
 
Posts: 7
Joined: Mon Aug 06, 2012 3:07 pm

Re: [newbie] Using JUCE with existing code

Postby chickeneps » Mon Aug 06, 2012 11:56 pm

Bruce Wheaton wrote:
chickeneps wrote:Remember, I already have a dylib project I want to use JUCE with. Is the task for me to make some type of faux pas IntroJucer project that has OggVorbisAudioFormat in it, get it to run, the copy-paste that code to my existing project?

Ah, so you have a library you want to use?
I suggest you start with something super dumb - just a blank window.


No, actually I have a fairly large dylib. It's not something I can reconstruct easily. I was just after being able to access JUCE FROM the project, not the other way around. And it does not have an interface, I'm just interested in the audio function code.

I did what TheVinn suggested and put in the select .cpp files and .h files, but I got a lot of compile errors when those .cpp files were compiling. I guess I have some work to do on that, nothing I can't handle.

I was sort of faked out by the outdated "INTEGRATING JUCE INTO A PROJECT" thing that was in the Overview, saying all that was needed was to include juce.h and another .cpp file (didn't say what it was). I still don't think it's accurate to say this is simple. Dealing with link errors isn't child's play sometimes. Static libraries and cpp's that are walking into an app always are going to have this problem, only .dylibs/dll's with .h files can avoid those type of errors.

Thanks for your help, I'll post back with good news shortly, hopefully.
chickeneps
JUCE Weenie
 
Posts: 7
Joined: Mon Aug 06, 2012 3:07 pm

Next

Return to General JUCE discussion

Who is online

Users browsing this forum: Bing [Bot] and 1 guest