Vcpkg使用MD运行时静态库——如何设置?

背景

vcpkg、conan等都是c++的包管理工具,且都是跨平台的,解决了c++程序员每次新建项目都需要拷贝代码依赖的痛点,就像前端npm一样,先search,然后再install,非常方便,再也不用配置include路径、lib路径了,点赞。

  1. vcpkg search <keyword>
$ vcpkg search http
apr[private-headers]                  Install non-standard files required for building Apache httpd
azure-uhttp-c        2020-12-09       Azure HTTP Library written in C
azure-uhttp-c[public-preview]         Azure HTTP Library written in C (public preview)
beast                0                HTTP/1 and WebSocket, header-only using Boost.Asio and C++11
brynet               1.0.7            A C++ header only cross platform high performance tcp network library, and sup...
cpp-httplib          0.7.18           A single file C++11 header-only HTTP/HTTPS server and client library
cpprestsdk[compression]               HTTP Compression support
curl[http2]                           HTTP2 support
curl[non-http]                        Enables protocols beyond HTTP/HTTPS/HTTP2
czmq[httpd]                           Build with HTTP server support (libmicrohttpd)
drogon               1.1.0            Drogon: A C++14/17 based HTTP web application framework running on Linux/macOS...
ecsutil              1.0.7.15         Native Windows SDK for accessing ECS via the S3 HTTP protocol.
evpp                 0.7.0#4          A modern C++ network library based on libevent for developing high performance...
fftwpp               2019-12-19       FFTW++ is a C++ header/MPI transpose for Version 3 of the highly optimized FFT...
http-parser          2.9.4            HTTP Parser.
ixwebsocket          11.0.4           Lightweight WebSocket Client and Server + HTTP Client and Server
ixwebsocket[mbedtls]                  SSL support (mbedTLS)
ixwebsocket[openssl]                  SSL support (OpenSSL)
ixwebsocket[sectransp]                SSL support (sectransp)
ixwebsocket[ssl]                      Default SSL backend
jaeger-client-cpp    0.5.1-1          C++ OpenTracing binding for Jaeger https://jaegertracing.io/
lapack-reference     3.8.0#4          LAPACK — Linear Algebra PACKage http://www.netlib.org/lapack/
lapack-reference[blas-select]         Use external optimized BLAS
lapack-reference[cblas]               Builds CBLAS
lapack-reference[noblas]              Use external optimized BLAS
libevhtp             1.2.18           Libevhtp was created as a replacement API for Libevent's current HTTP API.
libevhtp[openssl]                     Support SSL for libevhtp
libevhtp[regex]                       Support oniguruma for libevhtp
libevhtp[thread]                      Support thread for libevhtp
libgit2[winhttp]                      SSL support (WinHTTP)
libmicrohttpd        0.9.63#4         GNU libmicrohttpd is a small C library that is supposed to make it easy to run...
libpmemobj-cpp       1.11             C++ bindings for libpmemobj (https://github.com/pmem/pmdk).
libpmemobj-cpp[benchmark]             build benchmarks
microsoft-signalr[cpprestsdk]         Add default Http and WebSocket implementations using CppRestSDK
nghttp2              1.42.0           Implementation of the Hypertext Transfer Protocol version 2 in C
opusfile[opusurl]                     Support decoding of http(s) streams
pistache             2019-08-05       Pistache is a modern and elegant HTTP and REST framework for C++. It is entire...
proxygen             2020.10.19.00    It comprises the core C++ HTTP abstractions used at Facebook.
rapidjson            2020-09-14       A fast JSON parser/generator for C++ with both SAX/DOM style API <http://rapid...
restclient-cpp       0.5.2            Simple REST client for C++. It wraps libcurl for HTTP requests.
restinio             0.6.13           A header-only C++14 library that gives you an embedded HTTP/Websocket server t...
rsocket              2020.05.04.00-1  C++ implementation of RSocket http://rsocket.io
sassc                3.6.1            SassC is a wrapper around libsass (http://github.com/sass/libsass) used to gen...
scylla-wrapper       2018-08-26-16... This is a wrapper around Scylla. It exports functions for IAT fixing, dumping ...
wpilib[cameraserver]                  Enables the CameraServer and CSCore libraries for manipulating USB Cameras and...
  1. vcpkg install <packge name>
$ vcpkg install restclient-cpp

Vcpkg使用静态库

通过上面的方式,如果是在windows下,默认安装的是动态库,如果我们需要使用静态库怎么办?

$ vcpkg install spdlog:x86-windows-static

在包名后面加上 :x86-windows-static 即可。

然后在VS2017中,配置工程,Vcpkg选择静态库:
在这里插入图片描述
此时,VS2017就会从x86-windows-static目录下查找include,链接等等。
在这里插入图片描述

静态库MD版本

Vcpkg默认使用的是MT版本,现在大多我们都会使用MD运行时来编译我们的程序:
在这里插入图片描述

  1. 要安装MD版本的静态库也非常简单,在后面加个 -md 即可:
$ vcpkg install spdlog:x86-windows-static-md
  1. 然后,VS2017项目的工程里面,配置Triplet,加上 x86-windows-static-md 即可。
    在这里插入图片描述

补充

bin目录莫名其妙多了些dll

如果使用vcpkg install <package name> 会使用动态库,在使用VS2017的时候,会自动拷贝这些依赖的动态库到生成目录。

怎么确定dll是来自于那个包

$ D:\Program Files (x86)\Terminus> vcpkg depend-info spdlog
fmt: 
spdlog: fmt

如上所示,如果使用spdlog,则bin目录下会有2个动态库:fmt.dll和spdlog.dll,但是因为spdlog是header only,所以只会有1个fmt.dll。

spdlog禁用fmt.dll

本身看重spdlog就是因为他是header only,没有依赖库,现在bin目录莫名其妙多了一个,有点奇怪。
我们可以通过VS2017,在 工程属性->C/C+±>预处理器->FMT_HEADER_ONLY,来实现去掉fmt.dll。

为什么要这么做?如果你的程序需要在古老的windows server 2008上运行,必须这么做

参考

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值