当前位置:网站首页>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);
#endif
stay 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 :
边栏推荐
- ReentrantLock、ReentrantReadWriteLock、StampedLock
- SFINAE
- What is the London Silver unit
- 海外仓知识科普
- Programming skills: script scheduling
- Daily question 3 (2): check binary string field
- Pri3d: a representation learning method for 3D scene perception using inherent attributes of rgb-d data
- The global chip market may stagnate, and China's chip expansion accelerates to improve its self-sufficiency rate against the trend
- All you want to know about large screen visualization is here
- Vscode uses yapf auto format to set the maximum number of characters per line
猜你喜欢
The global chip market may stagnate, and China's chip expansion accelerates to improve its self-sufficiency rate against the trend
Synchronized与锁升级
阅读别人的代码,是一种怎样的体验
ThreadLocal之强、弱、軟、虛引用
Programming skills: script scheduling
Hyperledger Fabric 2. X custom smart contract
Teach you how to package and release the mofish Library
海量数据!秒级分析!Flink+Doris构建实时数仓方案
Privacy computing fat offline prediction
Semaphore of thread synchronization
随机推荐
PR second training notes
How to select cross-border e-commerce multi merchant system
Different perspectives
Reflection learning summary
Is there any discount for opening an account now? Is it safe to open an account online?
Atomic operation class
Synchronized与锁升级
Pisa-Proxy 之 SQL 解析实践
图书管理系统
AbortController的使用
Leetcode 724. Find the central subscript of the array (yes, once)
Too many requests at once, and the database is in danger
隐私计算FATE-离线预测
Top ten Devops best practices worthy of attention in 2022
Synchronized and lock escalation
隱私計算FATE-離線預測
LVI: feature extraction and sorting of lidar subsystem
[high concurrency] deeply analyze the callable interface
老师能给我说一下固收+产品主要投资于哪些方面?
Library management system