Static library usage steps:
Static libraries run only at compile time.
Method one:
First of all, the header file simply declares that the function questions and so on can be made into a static library and then called by the user.
Now I’m going to make a static library: the function of this static library is to convert input integers into binary output.
Step1:
In VS2013, first create a LB project and then add a. C file, which implements the conversion function. Source code is as follows:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
void msg()
{
int num;
Printf (” Please enter an integer :”);
scanf(“%d”, &num);
int data = 1 << 31;
0000 0000 0000 0000 0000 0000 0000 0000
// Determine positive and negative numbers
if (num < 0)
{
num = ~num + 1; / / the original code
num = num | data; // Get the symbol bit
}
for (int i = 1; i <= 32; i++)
{
int temp = num&data;
if (temp == 0)
{
putchar(‘0’);
}
else
{
putchar(‘1’);
}
num <<= 1;
if (i % 4 == 0)
{
printf(” “);
}
/*if (i % 8 == 0)
{
printf(“\n”);
} * /
}
system(“pause”);
}
Then add a header file to call MSG (); Write.
Step2: Then click Solution -> Properties -> Configure Properties -> General -> Project Defaults and change the project type to static library.
Step3: generate a solution.
Next in the new project, write the file call library. Copy the previous lb.lib library file to the current file directory. Most importantly, right-click Project Solutions -> Properties -> Linker -> Input -> Attach dependencies and add the name of the library file lb.lib to the front.
Method 2:
#pragma comment(lib, “lb.lib”)
Add this line directly to the source code of the file that needs to be connected to the static library.