Posts

Showing posts with the label static library

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...

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

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...

Create C Program with Static Library in Linux

Consider the following C program: #include <stdio.h> #include <math.h> double tvm (double rate, int terms, double principal); int main ( ) { double myrate; int myterm; double myprincipal; double myreturn; printf ("Please enter the following:\n"); printf ("Rate of return:(divide by 100, 4% is 0.04) "); scanf ("%lf", &myrate); printf ("\n"); printf ("Number of terms:(No decimals): "); scanf ("%d", &myterm); printf ("\n"); printf ("The principal amount: "); scanf ("%lf", &myprincipal); printf ("\n"); myreturn = tvm (myrate, myterm, myprincipal); printf ("Your return after %d term is $%.2lf.\n", myterm, myreturn); return 0; } double tvm (double rate, int terms, double principal) { double dn; double pp; dn = terms; pp = pow (1+rate, dn); return principal * pp; } You can place the tvm (Time Value of Money) function into ...

Create C Program with Static Library using Command Line in Windows

Image
The following procedure is to create C program with static library using Microsoft Visual Studio Express 2012 command prompt. For brief introduction to software library, please refer to the previous post Create C Program with Static Library using Visual Studio . Click here for procedure of creating a C program using Visual Studio . Example: The following example is a normal C program with functions without using any custom static library.  #include <stdio.h> #define PI 3.1415; double PowerOf2 (double UserNumber); double PowerOf3 (double UserNumber); double CircleArea (double UserRadius); double CircleCircum (double UserRadius); int main ( ) { double p2 = 10.0; double p3 = 5.0; double radius = 4.0; printf ("The number %.2f to the power of 2 is %.2f. \n", p2, PowerOf2(p2)); printf ("The number %.2f to the power of 3 is %.2f. \n", p3, PowerOf3(p3)); printf ("A circle with a radius of %.2f, the area is %.2f. \n", radius, CircleArea(...

Create C Program with Static Library using Visual Studio 2012

Image
The following procedure is to write and compile C program with a static library using Microsoft Visual Studio 2012 Express edition. For instruction on creating a basic C program using Visual Studio, please refer to the document here . Brief Introduction to Software Library A software library is a collections of previously written functions or program which can be reused. A C program always includes a  standard file called stdio.h. This file is the header file that describe all the pre-written function such as printf that comes with the compiler. This library file is also known as the system library. Library file that are created by users are called custom library. There are two types of library, static library and dynamic link library. Both library files can share their codes and function with other program. A program that link with a static library will include all the program required during compilation time. After which you can ship the execution (exe) program to the us...