当前位置:网站首页>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 :

边栏推荐
- CAS之比较并交换
- Gaode map IP positioning 2.0 backup
- Je veux acheter des produits à revenu fixe + mais je ne sais pas quels sont ses principaux investissements.
- 海外仓知识科普
- Redis 主从复制、哨兵模式、Cluster集群
- Web chat room system based on SSM
- What is the London Silver unit
- Teach you how to realize pynq-z2 bar code recognition
- Massive data! Second level analysis! Flink+doris build a real-time data warehouse scheme
- Top ten Devops best practices worthy of attention in 2022
猜你喜欢

CAS之比较并交换

The global chip market may stagnate, and China's chip expansion accelerates to improve its self-sufficiency rate against the trend

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

Talk about redis transactions

基于WEB平台的阅读APP设计与实现

巧用redis实现点赞功能,它不比mysql香吗?

PostgreSQL 15新版本特性解读(含直播问答、PPT资料汇总)

隱私計算FATE-離線預測

阅读别人的代码,是一种怎样的体验
![[WUSTCTF2020]girlfriend](/img/a8/33fe5feb7bcbb73ba26a94d226cc4d.png)
[WUSTCTF2020]girlfriend
随机推荐
Brief reading of dynamic networks and conditional computing papers and code collection
Use GCC to generate an abstract syntax tree "ast" and dump it to Dot file and visualization
élégant pool de threadpoolexecutor personnalisé
Je veux acheter des produits à revenu fixe + mais je ne sais pas quels sont ses principaux investissements.
原子操作类
Four characteristics of transactions
The global chip market may stagnate, and China's chip expansion accelerates to improve its self-sufficiency rate against the trend
Daily 3 questions (1): find the nearest point with the same X or Y coordinate
522. 最长特殊序列 II / 剑指 Offer II 101. 分割等和子集
All you want to know about large screen visualization is here
Experience sharing of mathematical modeling: comparison between China and USA / reference for topic selection / common skills
关于 SAP UI5 参数 $$updateGroupId 前面两个 $ 符号的含义
R language objects are stored in JSON
老师能给我说一下固收+产品主要投资于哪些方面?
June 27, 2022 Daily: swin transformer, Vit authors and others said: a good basic model is the simple pursuit of CV researchers
ReentrantLock、ReentrantReadWriteLock、StampedLock
Redis persistence
Multithreading Basics (III)
Step by step expansion of variable parameters in class templates
R language triple becomes matrix matrix becomes triple