Dev-C ++ in the use of static link library

Dev-C ++ in the use of static link library

In Dev-C ++, the suffix static link library is .a, this is not the same and VS lib.

I. First, we create a static link library project,
a new CPP file square.cpp

code:

class Square{
public:
float Area(float width,float height);
};

float Square::Area(float width,float height){
return width * height;
}

This class defines a method of calculating the area of a rectangle.
Compiler which generates the correct project name and the same SquArea.a library file. Note that this is not a code file name but the name of the project.

Second, using static libraries
to create a new console project, create a new header file square.h
class where the pasted defined above:

code:

class Square{
public:
float Area(float width,float height);
};

The header file referenced in the entry main.cpp years,

code:

#include <iostream>
#include "area.h"
using namespace std;

main int (int argc, char ** the argv) {
a float width = 0;
a float height = 0;
COUT << "Please enter a width of a rectangle:" << endl;
CIN >> width;
COUT << "Please enter rectangular high: "<< endl;
CIN >> height;
Square Square;
COUT <<" area = "<< square.Area (width, height ) << endl;

system("pause");
return 0;

}

Third, set the link parameters
into the parameters set project properties, add the following link fence
./Squarea.a

The meaning here is the link when the current directory Squarea static link library to join.

Finally compile and run, complete.

Guess you like

Origin blog.51cto.com/1685766/2479173