centos5.8,g++4.1.2
More recent operations, small pen down
Static libraries, dynamic library compilation and linking
1.dynamicmath.h
Class Dynamicmath
{
Public
Static double Add (double A, double b);
Static double sub (double A, double b);
void print ();
};
2.dynamicmath.cpp
#include "DynamicMath.h"
#include <iostream>
Using Std::cout;
Using Std::endl;
Double Dynamicmath::add (double A, double b)
{
return a+b;
}
Double Dynamicmath::sub (double A, double b)
{
return a-B;
}
void Dynamicmath::p rint ()
{
cout<< "Dynamicmath" <<endl;
}
3.main.cpp
#include <iostream>
using namespace Std;
#include "DynamicMath.h"
int main ()
{
Double A = 10;
Double b = 2;
cout<< "A + b=" <<dynamicmath::add (A, b) <<endl;
cout<< "a-b=" <<dynamicmath::sub (A, b) <<endl;
Dynamicmath dy;
Dy.print ();
return 0;
}
4.makefile
All:main Smath Smain Dmath dmain
Main
g++-o main main.cpp DynamicMath.cpp
Smath:
g++-C DynamicMath.cpp
AR-RSV libsmath.a DYNAMICMATH.O
Smain:
g++-o smain main.cpp-l./-lsmath
Dmath:
g++-fpic-shared-o libdmath.so DynamicMath.cpp
Dmain:
g++-o dmain-l./-ldmath main.cpp-wl,-rpath.
Clean
Rm-f *.O
Rm-f *.a
Rm-f *.so
Rm-f Main
Rm-f Smain
Rm-f Dmain
GCC Static Dynamic Library compilation