Saturday, March 7, 2009

Using Ant to compile C programs on Mac

Ant is a powerful java based build tool that is an alternative for make, nmake and others. Here are the steps that I've followed to build C programs using "ant" on a Mac OS X system.

1. Downloaded "Ant 1.7" from http://ant.apache.org/ and extracted it into my home folder.
2. Downloaded "cpptasks" from http://ant-contrib.sourceforge.net/cpptasks/ and extracted it under my home folder.
3. Updated the PATH, and set ANT_HOME environment variables like below
     $bash
    $export ANT_HOME= {path to ant folder} 
    $export PATH=$PATH:{path to ant folder}/bin
4. Ran "ant" from within to build/create "cpptasks.jar"
5. Copied "cpptasks.jar" from {path to cpptasks folder}/target/lib into {path to ant folder}/lib. Updated the CLASSPATH with this jar-file-name like below
$export CLASSPATH=$CLASSPATH://lib/cpptasks.jar

6. Created a simple C program in a path like
./src/main/c/Hello.c
7. Created a simple build.xml as given in http://ant-contrib.sourceforge.net/cpptasks/
8. Ran "ant" and it created the executable under "./target" as specified in the build.xml.

Hope this helps someone.

No comments:

Post a Comment