Saturday, May 29, 2010

c++ - create personal library(linux platform)

/*create own personal library in c++, using gcc compiler in linux platform.
atfirst create a source file and a header file. then create a main file to
include header file. here function.cpp is source file and function.h is header
file. main.cpp is main file. */
//note : - use '>' & '<' as ']' & '[' respectively.
//"function.h"
int sum(int a,int b);

//"function.cpp"
#include"function.h"
int sum(int a,int b)
{
return a+b;
}
//then compile source file function.cpp as gcc -c function.cpp
//it creates object file function.o

//"main.cpp"
#include[iostream]
#include"function.h"
using namespace std;
int main()
{
cout[["sum is "[[sum(3,5)[[endl;
return 0;
}
//compile it as "g++ -Wall main.cpp function.o"
//and then run as "./a.out" the result "sum is 8".


//

No comments:

Post a Comment