I can't make sense of open sorce code

Is there any good tutorials or documentaries on understanding c++ open source programs? I tried looking at vlc and had no clue what was going on so I decided to take a look at regshot which is a much simpler program and still couldn't understand anything. Is there a good book or tutorial or anything that helps with multi-file (and linux based considering they are all packaged to be tar-ed on linux)? I'm not particuarly gifted in c++ but I can hold my own when it comes to writing a relatively advanced piece of code.
Thanks for the help.
closed account (S6k9GNh0)
Every function, variable, or define called must be defined in some sort or fashion in a file related to location called. Read each line and carefully and slowly understand where and why everything is being called. After a while, you'll get a feel of it, and you should be able to read a majority of the rest of the code with a minor understanding. Not all C++ code is the same, so just because you have experience, doesn't necessarily mean you can jump into any program and understand everything.
Start with something small, like libcurl or getopt or something like that.

You need to get used to the style and the autoconf/automake stuff. There's a huge learning curve, but you'll eventually take it in your stride.
I still don't know where to start when I get a gz file. Is there a main program that the compiler starts from like main.cpp? Looking at the makefile doesn't help at all
*.gz files are compressed archive files - like *.zip or *.rar
If you're on Linux, download the a file. It'll look something like netcat-1.10-2.tar.bz2.

You extract the code like:
tar -xjvf netcat-1.10-2.tar.bz2

or if it's a gz file:
tar -xzvf netcat-1.10-2.tar.gz

change directory to the newly created netcat directory.

Run ./configure
This will create the build system.

Run make
This will compile the code.

You can always look around the directory tree and look at/modify the source code.
Last edited on
closed account (S6k9GNh0)
./configure && make && make install && make clean

Usually the commands called in order if supported by the make file (should be if your using configure).
Last edited on
You extract the code like:
tar -xjvf netcat-1.10-2.tar.bz2

or if it's a gz file:
tar -xzvf netcat-1.10-2.tar.gz


If the extensions are accurate, then a tar -xvvf <archive-name> would suffice, whether it is a gz or bz2 archive.
I think OP is having problems understanding how to read the code, not building it or unpacking it.

The compiler can compile the sources in any order. The only way you can know where the execution starts is by searching main. Conventionally, the entry point is in main.c*, or programName.c*.
Remember that main() isn't necessarily the first function called.

There aren't really any shortcuts to understand code. One option could be emailing the maintainer and politely asking which function performs the action you're interested in.
Last edited on
Also, a lot of the time OS code is not very well written...
http://www.amazon.com/Code-Reading-Open-Source-Perspective/dp/0201799405

is supposedly an amazing book, i'm planning on reading it soon
it won a jolt productivity award

you can check gigapedia for a pdf...
Topic archived. No new replies allowed.