Friday, 27 August 2010

Creating a dylib file in XCode

!--main.c file

#define EXPORT __attribute__((visibility("default")))



__attribute__((constructor))
static void initializer(void)
{
printf("%s",__FILE__);
}
__attribute__((destructor))
static void finalizer(void)
{
printf("%s",__FILE__);
}

EXPORT

void shownow (void) {
// insert code here...
printf("Hello, World!\n");
}

Use EXPORT before any funtion that you would like to export in dylib file. After you have written the file. You can create a dylib in terminal by typing the command below.
Locate the main.c file and type


gcc -dynamiclib -std=gnu99 "FileName" -current_version 1.0 -compatibility_version 1.0 -fvisibility=hidden -o "LibFileName"

Example:
"FileName" - main.c
"LibFileName"- main.dylib

No comments:

Post a Comment