Saturday, May 16, 2009

Build a static C library and link to an executable



At various stages in my programming career I did security coding in C and C++. Recently I discovered a hash function library from security guru Bruce Schneier, called Skein.

My friend Ricardo Machado kindly provided me a command line test utility he wrote for Skein. My objectives were, using XCode development environment:
  • Compile Skein as a static library
  • Compile the test program and link to Skein static library
The major issue for me is to have the static library project referenced by the test executable project, so that when library code changes and the test program is rebuilt, both library and test executable's binaries are updated and re-linked automatically. This is standard 'make' logic, and it wasn't easy to discover under XCode.

It is fairly easy to create individual projects from XCode, one for static library and the other for the test app, ie. "libskein.a" and "test" respectively. Once you do that, open the test project, then drag and drop library project file "skein.xcodeproj" under "test" project:

Then go to "Targets" under XCode navigation tree and select "test". Right-click and select "get Info":

Click the "+" button and add a relative reference to libsekin.a. This will ensure that libskein is built and re-linked with test whenever necessary.

Other References:

No comments:

Post a Comment

iTerm2 - How to auto-close sessions and auto-exit when last one closed

 Problem There are two problems when you close sessions and windows in ITerm2. When you gracefully exit from ITerm2 sessions with a recommen...