Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Even though I've written quite a bit of software myself, and consider myself relatively knowledgable, computer-wise, I have never successfully built someone else's project from source. NEVER. And I've tried--oh, I've tried. There are always missing header files, obscure errors, ridiculously long chains of dependencies. If something actually compiles, it'll crash on launch.

It's safe to assume that not every open source project out there is broken, and that therefore, it's me. Are there any tutorials or suggestions for dealing with the general process of building a project from source? Or does it usually work when one follows the instructions, in which case I'm apparently cursed?

share|improve this question
Can you maybe rephrase the question so as to be more specific about what you want a user to actually answer? Would you like us to write a tutorial, provide you with information, give suggestions as to where you may be messing up? – Jonathan Aug 6 '10 at 8:55
up vote 2 down vote accepted

Please note that this is a rough outline as projects can vary very much.

Probably the most common cause of failure is indeed dependencies, or lack of code portability.

First be sure to have the latest XCode installed.

I'd recommend using either MacPorts or Homebrew at first. This will give you access to many open-source packages out of the box.

Then, if your project is not in the provided package list, the aforementioned package managers will allow you to install its direct dependencies (and in turn their dependencies, recursively) much more easily than building said dependencies from source by hand.

Next two choices are offered to you:

  1. you build and manage the project by hand
  2. you create a portfile (MacPorts) or a formula (Homebrew), allowing for the package management to fetch, build, install and manage your project

How to build your project very much depends on the project itself and the language it is written in. Instructions generally lie in a INSTALL or README file.

Since you talk about header files I suppose it's a program written in C or C++. In that case the build process is generally as follows:

./configure --prefix=/usr/local

Be sure to set a prefix so as not to overwrite system stuff in /usr/bin for projects using insane defaults.

If all dependencies are satisfied the configure script should proceed successfully, and so should do make. If problems occur, you can point to or disable dependencies with the configure script, relevant flags given by ./configure --help.

Once the compilation has succeeded, you can proceed to either install via sudo make install.

Alternatively, try to build a portfile or a formula which will do the building steps, but managed by the package manager.

The package manager route has many advantages:

  • the build commands are easily reproduced for a newer version of the project
  • the uninstallation is quite easily handled
  • you can contribute back the portfile/formula
  • you can take inspiration from an existing portfile/formula written for a similar project to successfully build your project

Resist the temptation to build Universal binaries. It can be a tricky matter which you should only attempt if you succeed and master regular builds first.

Be aware though that some projects are not written in a portable way (either by necessity, irrelevance, or lack of will) and will just fail to build on Mac OS X. Although not trivial, this could be an opportunity to learn and port the code to a new platform...

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .