Monthly Archives: August 2011

Creating and using dylib (.so) files with XCode

I am currently developing on 3 platforms at work so I am trying to manage the source code in a tidy manner and version each module etc… Shared object files in linux and dll’s in windows have always been pretty easy but I have not tried to created a dylib (.so equivalent) in mac xcode before. I have made it work, im not sure if its the correct way but its linking and runs.

First i had a standard command line program that I wanted as a library so I went to the project settings and changed Mach-O Type to Dynamic library. This means the compiler does not look for a main function.

Next I need to rename the output file. For this I find the target in the project explorer, right click and get info, build tab. In the packaging sections change Product name to name.dylib. Build the project and it should now produce you a shared library file.

To use this library in another project you need to make a few further steps.

First add the associated header file directory to the header search path in the project settings.

Secondly add the directory of the library file to the library search path.

Finally create a new group in the project explorer named “libs” or something similar and drag the library file to this group. When you build it should all link up and execute. I have had some issues where the executable cannot find the library. With a brief googling it seems that xcode at least at one time had a conflict of build versions unless the library file is not in the execution directory. I hope to resolve this, but for now I just copy the library file over.

Printf makes my PC beep!

Ive been setting up TCP communication between windows 7 and my mac and I get kept getting a ringing sound when sending a certain packet. With some more investigation it turns out at a printf with a “\a” or ASCII 7 produces a beep to occur from the system. Im really not sure why I would want this to ever happen, and its really off putting to hear your code beep all the time!