当前位置:网站首页>使用VS创建静态链接库.lib并使用
使用VS创建静态链接库.lib并使用
2022-06-29 04:44:00 【咖啡与乌龙】
一、使用VS创建静态链接库.lib
创建一个VS项目
* 可以是一个空项目或VS中自带的静态库项目模板

*
空项目中没有原始代码或文件,我优先选择这种模式*
静态库项目有一些原始代码和文件,其中pch.h是预编译标头文件,用于加快编译性能;framework.h文件也是自动生成的可以不用管设置相应的编译选项
*
空项目:项目属性—配置属性—常规—配置类型—选择静态库(.lib)*
配置和平台可以选择Debug、Win32或其他设置,调用方使用相同配置即可
* 额外提醒:工具栏的配置和平台选择与上述属性界面的配置和平台选择是一个东西

添加代码并生成
* 添加需要的
头文件(.h)和源文件(.cpp)
* 编译生成即可结果
生成之后,可以根据输出提示找到相应的
.lib文件的位置
静态库项目:已经默认设置配置类型为静态库(.lib)了,其原有的文件可以不用动,另外添加头文件(.h)和源文件(.cpp)即可
二、在项目中使用静态链接库.lib
方式一:
复制静态库的
头文件(.h)和库文件(.lib)至项目目录复制到项目目录后,将
头文件.h添加进项目:头文件—添加—现有项—找到头文件进行添加在项目属性中添加
库文件(.lib)项目属性—配置属性—链接器—输入—附加依赖项—将库文件名写进去即可
在代码中包含
头文件(.h)// main.cpp文件中 #include "LibTest.h" //假设我的文件名字是LibTest.h注意事项:
库使用的平台(x64、x86)和配置(release、debug) 应和调用方项目一致
方式二:不依赖于VS平台,在代码层面调用
#pragma comment(lib, "LibTest.lib") // 当库文件处于项目所在目录时,使用的是相对路径
#include "LibTest.h"
#pragma comment(lib, "D:\\桌面\\LibTest.lib") // 也可以使用绝对路径
#include "LibTest.h"
方式三:直接将lib添加进项目的资源文件中

边栏推荐
- Research Report on the overall scale, major manufacturers, major regions, products and applications of electric hydrofoil surfboards in the global market in 2022
- Cisco voice card handling configuration
- Visitor pattern
- Blue Bridge Cup ruler method
- 《软件体系结构》期末复习总结
- Practical part: solving the function conflict between swagger and user-defined parameter parser
- Canoe- how to parse messages and display information in the trace window (use of program node and structure type system variables)
- [C language] start a thread
- How to create robots Txt file?
- 轻松入门自然语言处理系列 专题7 基于FastText的文本分类
猜你喜欢

基于.NetCore开发博客项目 StarBlog - (13) 加入友情链接功能
![[Verilog quick start of Niuke network question brushing series] ~ asynchronous reset Series T trigger](/img/e3/cf40fb0131ddeb26bc5beeca03d183.png)
[Verilog quick start of Niuke network question brushing series] ~ asynchronous reset Series T trigger

Real time waveform calculation function of Waveform Recorder mr6000

没遇到过这三个问题都不好意思说用过Redis

Mvcc principle in MySQL
![[hackthebox] dancing (SMB)](/img/bb/7bf81004b9cee80ae49bb0c0c2b810.png)
[hackthebox] dancing (SMB)

Mediator pattern

Live broadcast appointment AWS data everywhere series activities

Agilent digital multimeter software ns multimeter, real-time data acquisition and automatic data saving

Observer pattern
随机推荐
CTO and programmer were both sentenced because the crawler was out of control!
ROS TF coordinate transformation Library & rewrite to create high frequency coordinate transformation broadcaster
20年秦皇島D - Exam Results(二分+思維,附易錯數據)
Matlab直接求贝塞尔函数的导函数
Research Report on the overall scale, major manufacturers, major regions, products and applications of electric hydrofoil surfboards in the global market in 2022
[Verilog quick start of Niuke network question brushing series] ~ asynchronous reset Series T trigger
How to display all MySQL databases
Technical parameters of Tektronix DPO4104 digital fluorescence oscilloscope
How to write MySQL scheduled backup script in Linux
Software architecture final review summary
Cisco voice card handling configuration
How to use the select statement of MySQL
LabVIEW显示Unicode字符
Webapck system foundation
Memo pattern
Hantai oscilloscope software | Hantai oscilloscope upper computer software ns-scope, add measurement data arbitrarily
《软件体系结构》期末复习总结
Apifox: it is not only an API debugging tool, but also a collaboration artifact of the development team
Accelerate the global cloud native layout, kyligence intelligent data cloud officially supports Google cloud
The last week! Summary of pre competition preparation for digital model American Games