Posts

Showing posts with the label C programming

Create C Program with Dynamic Library using Xcode in Mac OS X

Image
The following instructions is a simplified procedure to create a dynamic library. Please note that the actual implementation of dynamic library is very complex if the library is very large and multiple users or versions are involved. Please consult the Xcode user guide for more information. Example The following program is a complete program that uses some math functions: #include <stdio.h> #define PI 3.1415; double CircleArea (double radius); double CircleCircum (double radius); double PowerOf2 (double number); double PowerOf3 (double number); int main ( ) { double r = 4.0; double n = 5.0; printf ("Radius %.2f, area is %.2f \n", r, CircleArea(r)); printf ("Radius %.2f, circumference is %.2f \n", r, CircleCircum(r)); printf ("%.2f to the power of 2 is %.2f \n", n, PowerOf2(n)); printf ("%.2f to the power of 3 is %.2f \n", n, PowerOf3(n)); return 0; } double CircleArea (double radius) { return radius * radius * P...

Create C Program with Dynamic Library using Command Line in Mac OS X

For those who are not familiar with static and dynamic library, the differences between static and dynamic library is the way it was compile and run. To use a static library, the application and the static library must be present during compilation. The compiler will extract the code from the static library and incorporated into the application program. You'll have only one application binary file. When using dynamic library, the compiler do not incorporate the code from the dynamic library into the application program. The application program will load the library during runtime. In this case, you'll need to deliver two binary files to the user; the main application binary and the dynamic library file. The advantages of using dynamic library are smaller application size since the library code is not incorporated in the application program and it may reduce memory usage when since the library is loaded only when the function is needed. There are two usage of dynamic ...

Create C Program with Static Library using Xcode in Mac OS X

Image
The following program is a complete program that uses some math functions: #include <stdio.h> #define PI 3.1415; double CircleArea (double radius); double CircleCircum (double radius); double PowerOf2 (double number); double PowerOf3 (double number); int main ( ) { double r = 4.0; double n = 5.0; printf ("Radius %.2f, area is %.2f \n", r, CircleArea(r)); printf ("Radius %.2f, circumference is %.2f \n", r, CircleCircum(r)); printf ("%.2f to the power of 2 is %.2f \n", n, PowerOf2(n)); printf ("%.2f to the power of 3 is %.2f \n", n, PowerOf3(n)); return 0; } double CircleArea (double radius) { return radius * radius * PI; } double CircleCircum (double radius) { return 2 * radius * PI; } double PowerOf2 (double number) { return number * number; } double PowerOf3 (double number) { return number * number * number; } We create a static library so that we could reuse all the custom math functions for other pro...