当前位置:网站首页>Creation and use of static library (win10+vs2022
Creation and use of static library (win10+vs2022
2022-06-27 14:59:00 【Alexabc3000】
The creation of static library
Use VS2022 New empty project , The project is called MyStaticLib, The folder where the project is located is “E:\temp”.

Click Create , That is to complete the creation of the project .
stay VS2022 Of “ Solution explorer ” In the view , Add name is “MyStaticLib.h”( The file name can be any ) The header file ( Right click “ The header file - add to - New item - The header file ”),

Enter the following code :
#ifndef _MY_STATIC_LIB_H_
#define _MY_STATIC_LIB_H_
int my_static_add(int a, int b);
#endifstay VS2022 Of “ Solution explorer ” In the view , Add name is “MyStaticLib.cpp”( The file name can be any ) Of C++ file ( Right click “ Source file - add to - New item -C++ file ”),
#include "MyStaticLib.h"
int my_static_add(int a, int b)
{
return a+b;
}In the project property page , Change the configuration type to “ Static library (.lib)”.

Build solution , The library file can be generated “ E:\temp\MyStaticLib\x64\Debug\MyStaticLib.lib”.
The use of static libraries
Use VS2022 New empty project , The project is called MyApp, The folder where the project is located is “E:\temp”.
stay VS2022 Of “ Solution explorer ” In the view , For projects MyApp Add name is “main.cpp”( The file name can be any ) Of C++ file ( Right click “ Source file - add to - New item -C++ file ”), Enter the following code :
#include <iostream>
// The header file containing the static library
#include "E:\temp\MyStaticLib\MyStaticLib.h"
int main()
{
int a = 3, b = 5;
int c = my_static_add(a, b);
std::cout << "my_static_add(" << a << "," << b << ") = " << c << std::endl;
return 0;
}
At this point, the solution is generated , A link error occurs , The error message is :
main.obj : error LNK2019: Unresolved external symbols "int __cdecl my_static_add(int,int)" ([email protected]@[email protected]), function main The symbol is quoted in
This is an error caused by the connector not finding the library file , The solution is :MyApp Project property page , The linker , Input , Additional dependency , Add dependency “E:\temp\MyStaticLib\x64\Debug\MyStaticLib.lib”

Build solution , The executable file can be generated “E:\temp\MyApp\x64\Debug\MyApp.exe”.
On the command line, enter the directory “E:\temp\MyApp\x64\Debug\”, function MyApp.exe, The operation results are as follows :

边栏推荐
- [business security-02] business data security test and example of commodity order quantity tampering
- Professor huangxutao, a great master in CV field, was born at the age of 86. UIUC specially set up a doctoral scholarship to encourage cutting-edge students
- volatile与JMM
- How to select cross-border e-commerce multi merchant system
- Using redis skillfully to realize the like function, isn't it more fragrant than MySQL?
- E-week finance Q1 mobile banking has 650million active users; Layout of financial subsidiaries in emerging fields
- AQS抽象队列同步器
- Excuse me, is it cost-effective to insure sunshine Optimus Prime term life insurance No. 7? What are the advantages of this product?
- Talk about redis transactions
- 做一篇人人能搞懂的ThreadLocal(源码)
猜你喜欢

Leetcode 724. Find the central subscript of the array (yes, once)

QT 如何在背景图中将部分区域设置为透明

Privacy computing fat offline prediction

AutoCAD - line width setting

CAS comparison and exchange

Talk about redis transactions

What is the London Silver code

AQS抽象队列同步器

初识云原生安全:云时代的最佳保障

How to select cross-border e-commerce multi merchant system
随机推荐
How is the London Silver point difference calculated
Volatile and JMM
Semaphore of thread synchronization
图书管理系统
Why can't the start method be called repeatedly? But the run method can?
Gaode map IP positioning 2.0 backup
Leetcode 724. 寻找数组的中心下标(可以,一次过)
Today, Teng Xu came out with 37k during the interview. It's really a miracle. He showed me his skill
ThreadLocal之强、弱、软、虚引用
老师能给我说一下固收+产品主要投资于哪些方面?
Li Kou's 81st biweekly match
SFINAE
Design and implementation of reading app based on Web Platform
Redis 主从复制、哨兵模式、Cluster集群
请求一下子太多了,数据库危
Overseas warehouse knowledge popularization
Design and implementation of food recipe and ingredients website based on vue+node+mysql
Julia1.1 installation instructions
Jupiter core error
注解学习总结