Compile problems -- understanding structure

I’ve been slowly chipping away at learning some very simple C++ and working with OF. I can write basic programs and get some basic things working and it’s super fun.

So then I try to start learning more by looking at examples, and at that point I can say that without a doubt the most time consuming part is dealing with compile errors, I spend about 90% of my time searching out missing libraries and addons, commenting or uncommenting includes in headers, trying different combinations of everything, wondering if it’s the version of OF I have checked out, basically not knowing what is going wrong and stabbing in the dark for hours on end. It feels like a very unproductive effort. (I know that some of this is just related to a “living” codebase)

It definitely feels like I’m missing some body of knowledge about how the directories should be structured, where they are supposed to be added to a project and in what hierarchy, header search paths, etc. I’ve followed the few snippets of help I can find on the subject for Xcode but I still end up having a lot of problems. I see different structures in different examples, sometimes I see addons/addOnName/src/, sometimes I see addons/addOnName/lib/ as well, sometimes it’s addons/addOnName/src/lib/, sometimes (as in the MSAlibs) There are folders within addons that don’t use the “ofx” prefix and leave me a bit unsure if they are addons or “libraries.” In general, custom-created “libraries” don’t always seem to go in the same place, and are a bit confusing to me as well.

I realize this is something that may just come with experience but I feel like I’m wasting a lot of time. Feels like I need to backup and get some more fundamental understanding. Is there a reference I can brush up on or something that will help me get back on track?

Thanks!

Yeah, thanks for this. I feel exactly the same way. I am a fairly experienced programmer, and these libraries and addons just constantly make me feel stupid.

I’ve just downloaded msalibs and have no idea how to get anything to work.

I completely understand your frustration, I used to feel this way as well and I still do sometimes for example when I am trying to incorporate an external library like the bullet SIMD Vector classes was terribly confusing and frustrating.

For oF addons at least it, there is a fairly standard way of doing it. The directory structure itself doesn’t really matter much. What matters is that your compiler and linker know where those header files are, so if they are in /addons/ofxWhatever/src or /addons/ofxWhatever/lib/src, just add the appropriate one where the .h files are.

I dont know what IDE you’re using but I’ll use codeblocks as an example because it is what i use. I’ll walk you through starting a new project the way that I do it. I’m sure many others do it many other ways but this makes the most sense to me right now.

Lets say you want to start with Empty example and modify it into something that uses, lets say ofxFBOTexture and ofxShader.
I start by copying the emptyExample folder from of /of/apps/examples to of/apps/myApps. This preserves the relative folder structure of all of the existing project properties. Then I’ll rename the empty example folder to whater name I’d like the project to be, lets call it /of/apps/myApps/myShaderApp.

Since this is based off of emptyExample, there are no addons already imported into the project. This process will vary based on your IDE and compiler, but they are generally similar.

There are two things you’ll need to do to get the addons working. First, import the source files from each addon. In codeblocks, click on the project menu, then add files, then find the addons/ofxShader/src directory and select all of the source files in there. Do the same for ofxFBOTexture or any other addon you want. The next step is to make sure that the compiler and linker know where these files are, click on the project menu, then build options, then click on search directories and add the location of wherever you found the source files. so if it was in /addons/ofxWhatever/lib/src, then you would want to add that directory.

Then, add #include “ofxShader.h” and #include “ofxFBOTexture.h” to testApp.h and you should be all set and ready to use the addon. From there, its a matter of finding an example of how the addon is used, which is a different problem entirely.

I have not used msalibs yet so I’m not sure how they differ from the built in addons, but I would suspect they are set up in a similar manner. One thing I do know about msalibs is that you will need to have MSACore.h setup in your project in addition to whatever specific addon you want to use.

I hope this helps, I know how frustrating it can be to face hundreds of lines of linker errors.

Thanks for this great explanation Tim.

I know the feeling. When i started with of and c++ in general I sometimes just couldn’t bare it anymore. But at some point it just clicked and everything sort of came together. Not that I’m absolute pro or whatsoever but I think at some point one just sees how it all relates. Because every library, be it of addon or not, is actually very similar, usually mad up of header (.h) files to include, .cpp or .c files to compile and occasionally a precompiled library (.a, .dynlib, .dll or .so) files to link.

Every program you create is first compiled and then linked. Compiling turns every .cpp file into machine language. Linking then takes all these generated files and combines them in one program.

If you get a “No such file or directory error”, it is a compiler error. So you are probably missing an .h file. Search for it on your computer and if you can’t find it, on the internet. If you have it you need to point your header search path to the folder the file is in. Where you put them basically doesn’t matter. but your compiler has to find them. A “was not declared in this scope” error is very simple and means that you are probably missing an #include statement, like #include “file where missing function is declared.h”. Or it can also be a simple typo :wink:

If you get something like " ‘name of the function’, referenced from: symbols not found" then it is a linker error. That means the linker is looking for a compiled cpp file that contains the code for ‘name of the function’ but can’t find it. Again search for the right file and make sure it is part of your project and compiles. If you can’t find it, it is probably part of a precompiled library, a set of compiled cpp files combined. Using a search engine you can usually find out to which library the function belongs to.
Also make sure you check the error output for any signs of ‘wrong architecture’. If you compile in 32 bit it sometimes happens that you add a 64bit library which won’t work and vice versa. That happend to me quite often. Expecially on a mac because os x and a lot of libraries for it are now 64bit but OF compiles in 32bit on a mac. You can get info about a library in terminal with the command " lipo -info ‘path to your .a file’ "

ofx libraries often wrap another c++ or c library up so they are more accesible. That’s why you sometimes have a folder with all files starting with ofxSomething and another one with completely different names. the ones with ofxSomething use them internally. so you need them in your project as well to use the ofx files.

About msalibs. I’m not sure but it might be that they are already using of 0.07 the one you can find on github. On the website is of 0.06, the current stable release. However a lot of people already use the 0.07 prerelease and even write libraries for it because it is fairly stable and adds a lot of really nice new functionality. So a few libraries already get released in a way they only work with the github version. This is usually the case if you get a “function not declared” or a “too few arguments” or “too many arguments” error. Because 0.07 introduces new ways of calling functions. for example ofSetColor(); IN 0.06 you can only call it with ofSetColor(int r, int g, int b, int alpha) in 0.07 however there are many ways, the classic one or for example with ofSetColor(0xFF0000); which is a hexcode or with ofSetColor(const ofColor); which is the new ofColor object.
Also msalibs cross reference themselves or other openframeworks libraries. So MSAPhysics needs MSAObjCPointer or ofxSimpleGuiToo needs ofxXmlSettings for example.

I don’t know any complete c++ learning sites but maybe it would be worth linking some in the wiki to help finding articles that show the fundamentals in an understandable way. Because I kinda found it hard to distinguish between more and lesser useful tutorials in the beginning…

I hope this is neither too cryptic nor too basic and helps somebody. If it doesn’t just keep on asking and posting your errors. Usually somebody is willing and able to help.

lg.ph