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

边栏推荐
- 直播预约|AWS Data Everywhere 系列活动
- How to quickly install MySQL 5.7.17 under CentOS 6.5
- CTO and programmer were both sentenced because the crawler was out of control!
- Matlab直接求贝塞尔函数的导函数
- Proxy mode (proxy)
- 【代码随想录-动态规划】最长公共子序列
- Gbase 8s must be a DBSA. Solution to failure to start due to path change
- Using assetstudio/unitystudio uabe, etc
- 笔记本访问台式机的共享磁盘
- Remediation for Unsafe Cryptographic Encryption
猜你喜欢

ROS TF coordinate transformation Library & rewrite to create high frequency coordinate transformation broadcaster

仿真與燒錄程序有哪幾種方式?(包含常用工具與使用方式)

How to create robots Txt file?

How to test electronic components with a multimeter

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

Developer scheme · environmental monitoring equipment (Xiaoxiong school IOT development board) connected to graffiti IOT development platform

Mysql 中的 mvcc原理

What is the method of connection query in MySQL

ROS URDF model is parsed into KDL tree

be based on. NETCORE development blog project starblog - (13) add friendship link function
随机推荐
【IoT】公众号“简一商业”更名为“产品人卫朋”说明
043. (2.12) what will happen if you become enlightened?
波形记录仪MR6000的实时波形运算功能
Research Report on the overall scale, major manufacturers, major regions, products and applications of semiconductor CMP wafer fixed ring in the global market in 2022
ECS 4 sync point, write group, version number
Software architecture experiment summary
How to solve startup failure due to insufficient MySQL memory
[hackthebox] dancing (SMB)
The subnet of the pool cannot be overlapped with that of other pools.
LabVIEW显示Unicode字符
Continue yesterday's plan: February 16, 2022
Airflow 2.2.3 containerized installation
[C language] start a thread
Remediation for Unsafe Cryptographic Encryption
【代码随想录-动态规划】最长公共子序列
Research Report on the overall scale, major manufacturers, major regions, product and application segmentation of disposable hearing aid batteries in the global market in 2022
Actual combat! Another opening method of magic modified swagger and knife4j
The last week! Summary of pre competition preparation for digital model American Games
docker 创建的 mysql8 怎么改密码
如何创建 robots.txt 文件?