adding code, include paths / addons in CB

As more people start to experiment with OF, we’ve realized we need much more basic info about how things in the IDEs work, so we’re going to try to create as much of that as possible.

Typically, there are three things that you’d like to do with any given IDE - add source code, add include paths, and linking info. This is because in c++, there are three things that happen when you compile code:

[list type=lower-alpha]

  • the preprocessor alters the code (anything with a #), and takes included files (#include) and adds them to a given file (recursively).

  • the compiler turns .cpp to .o files (compiles them to object / assembly code).

  • the compiler links .o files together to make an application, and links in any compiled code from libraries that are needed.
    [/list]

if are adding something to an openframeworks project:

  • because of (a), we need to add include paths for a given project, so it knows where to find referenced files.

  • because of (b) we need to add source code to our project if we want that to be part of a project.

  • because of (c) we need to add **linking info **if it’s necessary to link against libraries.

I’m going to show you how this work, with a given addon (in this case, the ofxVectorGraphics addon). you can always look at the examples that come in the FAT package, to get a feeling for how this works and we encourage you to poke around the project settings of any OF projects, to see how they are put together. Sometimes just comparing two project files can show you the difference pretty clearly.

Also, we do recommend folks to copy addons example (ie, duplicate the examples in addonsExamples and rename them) to start, but it’s useful to know how to add these things by hand as well, so here we go:

first, for the ofxVectorGraphics addon, open up the install.xml file in your OF_FAT*/addons/ofxVectorGraphics/ (* = name of the fat package you’ve downloaded). This file is essenitally a list of files to add to the project, include paths to add, and linking (if there is compile code, right now this is just for ofxOpenCv and ofxOsc). It’s xml so that it could be automated, and is also human readable.

ok, let’s open up the xml file in a text editor:

so in “”, there is src we need to add (from src and libs folder inside the addon).

I would highlight the addons folder in the project broweser (left side of the IDE) and go to menu, project → add files:

choose it:

the folders in the install.xml are just suggestions for how you might organize the code, but the compiler doesn’t really care how it looks in the browser (left side of the IDE).
sometimes, CB displays the files in a wonky way, you can right click the broswer to alter file display. different folks like to work in different ways with CB (again this is just a visual appearance, and can help you navigate code). I typically try to mirror the folders on the hard drive:

if you need to add folders, you can via:

now, according the install.xml file, we need to add search paths for the two folders in the ofxVectorGraphics addon. you can do this, by menu project → build options. be sure to choose “testProject” or whatever you project is called and not release or debug (ie, add the paths to both debug and release targets):

add these two paths:

that’s it – now we can use ofxVectorGraphics in the code, and it should compile AOK.

If you need to alter linking, you can do that also in project → build options:

I hope these screenshots help people that are working with CB. We’ll do our best to try to add as much of this info as we can.

have fun!

Hi Zach,

Thanks for this little tutorial here. Is there some kind of trick to getting Codeblocks to stick the source code files into the directory you have highlighted in the project browser? It keeps putting them all in these Sources and Headers folders at the top level of the project regardless of what I have highlighted, which leads to manually moving lots of files one at a time to where I actually want to organize them (Codeblocks doesn’t support ctrl-clicking multiple files!).

-Aaron

sometimes, CB displays the files in a wonky way, you can right click the broswer to alter file display.

yeah, have not found this option for month… thanks zach

@aaron: this is the solution for you, also

project -> project tree -> deactivate “Categorize by file types”

Thanks Zach!

I just want to add to this that you have to add all the files in the src directory AND all the files in the libs directory to your project.

I know you mention this as well: "so in “”, there is src we need to add (from src and libs folder inside the addon). " but in your screenshots you only add the files in the src directory.

It actually took me 30 minutes to figure this out… :wink:

and, thanks to fxlange as well, that looks just so much better!

I’m not sure if I’m having the same issue you’re adressing here, but I got the following problem:

When I test any of the examples in the “openframeworks/apps/examples/” folder everything works perfectly fine. Ofcourse I want to to build projects in a different folder aswell, this doesn’t goes as planned unfortunately.

When I copy the “emptyExample” to a different folder I get a whole bunch of errors, the first one being “error: ofMain.h: No such file or directory|” which kind of explaines the rest of the errors, the openframeworks library is simply not found if I’m correct.

Now i’m new to c++ and codeblocks so I’m having some difficulty pointing the software to the openframeworks folder without editing all the include paths.

Any help here? I’m a big newbie so I’m afraid you will need to explain to me as if i’m a five year old haha.

Thanks in advance.

you don’t need to edit your search paths, just mantain your applications inside the OF folder at the same level than the examples. they don’t need to be in examples but something like:

openFrameworks
|_apps
|_examples
|_emptyExamples
|_myApps
|_myExample

where myExample is the new app you want to create and myApps a folder where you place all your applications

A big thanx for this posting this topic and to all who contributed to it.

PS: I’m very impressed with OpenFrameworks and the dedication and humbleness of the OF team and community.

hello
thanks for the post , i was getting disappointed before i saw this!
i have asked a question before but seems like i closed the page before i sent it as i cant find it anywhere! anyway…
i’m having difficulties finding gst/gst.h as compilers error says : gst/gst.h no such file or directory
seems like many people have the same problem, been looking into different forums but havnt found the answer yet!
i have libgstreamer0.10-dev already installed,been trying to get gstreamer, no luck!
can someone tell me how to solve this error please?!
thanks
ps: im using linux mint , LISA

Hi there,

thanks for the detailed intro! I’ve added ofxOsc to my project and just had trouble with the linking info in C::B v10.05 on Win7. Got the error:

  
to undefined reference to `WSAEventSelect@12'  

Although I had added

  
../../../addons/ofxOsc/libs/oscpack/lib/win32/oscpack.a  

as described in the install.xml coming with the ofxOSC addon. Fortunately this could be resolved by changing the order of linker parameters, as described here:

Hope it helps anyone as it helped me.

Hi!

i just found out, that the paths in the xml-file are not up to date!
in version 0071 the xml-file for ofxOpenCv says:

../../../addons/ofxOpenCv/libs/opencv/lib/win32/libcv.a ../../../addons/ofxOpenCv/libs/opencv/lib/win32/libcxcore.a

the files do not exist.
and the path does not exist.

win32 has been replaced with win_cb.
dunno what to add to the linker?

maybe someone can give me a hint here :slight_smile:

thanx