当前位置:网站首页>使用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添加进项目的资源文件中

边栏推荐
- Five thousand years of China
- Quelles sont les méthodes de simulation et de gravure des programmes? (comprend les outils communs et la façon dont ils sont utilisés)
- 如何创建 robots.txt 文件?
- 1019 digital black hole
- Facade pattern
- 泰克TDS3054B示波器技术指标
- Research Report on the overall scale, major manufacturers, major regions, products and application segments of semiconductor wafer metal stripping platform in the global market in 2022
- Research Report on the overall scale, major manufacturers, major regions, products and application segmentation of GPS antenna modules in the global market in 2022
- 开启生态新姿势 | 使用 WordPress 远程附件存储到 COS
- 【HackTheBox】dancing(SMB)
猜你喜欢

网传广东一名学生3次考上北大,3年共赚200万元奖金

泰克TDS3054B示波器技术指标

Facade pattern

LabVIEW displays Unicode characters

MySQL subquery

Alibaba microservice component Sentinel

Apifox: it is not only an API debugging tool, but also a collaboration artifact of the development team

笔记本访问台式机的共享磁盘

Open source demo| you draw and I guess -- make your life more interesting

Five thousand years of China
随机推荐
泰克DPO4104数字荧光示波器技术参数
什么是匿名内部类,如何使用匿名内部类
Live broadcast appointment AWS data everywhere series activities
Gbase 8s must be a DBSA. Solution to failure to start due to path change
How to use the select statement of MySQL
Practical part: solving the function conflict between swagger and user-defined parameter parser
1018 hammer scissors cloth
How to create robots Txt file?
没遇到过这三个问题都不好意思说用过Redis
Five thousand years of China
安捷伦数字万用表软件NS-Multimeter,实时数据采集数据自动保存
Redis 缓存穿透、缓存击穿、缓存雪崩
The people's Bank of China printed and distributed the notice on supporting cross-border RMB settlement of new foreign trade formats
Real time waveform calculation function of Waveform Recorder mr6000
Force deduction solution summary 324- swing sequencing II
[C language] explain the thread exit function pthread_ exit
[结构力学] 结点承载下影响线与直接承载下影响线不同的原因
Software architecture final review summary
Research Report on the overall scale, major manufacturers, major regions, products and applications of power battery laser welding machines in the global market in 2022
Research Report on the overall scale, major manufacturers, major regions, products and application segments of 5g modules of the Internet of things in the global market in 2022