vcpkg下载mysql库_VCpkg 开源库管理工具
VcPkg & MinGW GCC
VCpkg 開源庫管理工具
Windows 下開發 C/C++ 程序,少不了編譯開源的第三方庫。比如用于網絡連接的高性能庫 libcurl、用于壓縮解壓的 zlib 等等。使用這些庫開發極大的方便了程序員,使得我們不必重復造輪子。由于這些開源庫絕大部分都來源于 Linux 系統,其工程文件、編譯系統都使用 gnu 系列工具,使得將其移植到 Windows 的 VC 開發環境下一直是難點。
還需要考慮預先編譯出哪種類型的開源庫程序,比如:Debug 還是 Release、動態庫還是靜態庫、MD 還是 MT、32 位還是 64 位。光是這三種組合就有 16 種可能性。如果像 libcurl 這種還要考慮是否引用其他開源庫的功能,那么編譯類型的組合會更多。
VCpkg 就是解決這個問題的:
自動調用 git 等工具下載開源庫源代碼;
源碼包的緩存管理和版本管理,可以升級版本;
緊密結合 CMake 輕松編譯;
依賴關系檢查,比如編譯 libcurl,會自動下載 zlib、openssl 進行編譯;
無縫集成 Visual Studio,不需要設置庫文件、頭文件的所在目錄,自動集成。
Visual Studio 全平臺支持,支持 Debug/Release、x86/x64 編譯,還支持 UWP、ARM 平臺的編譯。
一般使用流程:
執行 vcpkg 安裝模塊,等待編譯動作完成;
執行 vcpkg integrate 集成到項目或者 Visual Studio,又或者全局集成;
在代碼中通過頭文件使用安裝好的模塊;
vcpkg 主目錄文件夾結構:
| buildtrees | 所有下載好的 library 源代碼和構建目錄 |
| docs | 文檔與示例 |
| downloads | 下載緩沖文件夾,執行安裝命令時會先查詢這里 |
| installed | 包含安裝好的 library 頭文件和編譯文件 |
| packages | 內部文件夾,在安裝時用到 |
| ports | 包含分類中的庫描述文件,包含版本、下載地址等 |
| scripts | 腳本目錄,如 cmake, powershell 腳本 |
| toolsrc | VcPkg C++ 源代碼和組件 |
| triplets | 包含支持架構配置文件,如 x86-windows、x64-uwp |
vcpkg 安裝依賴模塊的基本執行流程:
環境初始化
下載源代碼,如果已經在 cache 中,則跳過下載環節
校驗文件有效性
解壓縮源代碼
利用配套工具配置源碼工程,如 cmake,如果是 ffmpeg 則用 msys2
執行 MSBuild 編譯源碼,一般會同時編譯 Release 和 Debug 版本。
把編譯好的文件拷貝到相關目錄中去,一般是 installed 目錄
如果沒有在 vcpkg 主目錄運行,可能會遇到 Error: Could not detect vcpkg-root。
使用 PowerShell 執行 Vcpkg 工程目錄下的 bootstrap-vcpkg.bat 進行編譯,會在同級目錄下生成 vcpkg.exe 文件。
命令使用示范:
>vcpkg --help
Commands:
vcpkg search [pat] Search for packages available to be built
vcpkg install ... Install a package
vcpkg remove ... Uninstall a package
vcpkg remove --outdated Uninstall all out-of-date packages
vcpkg list List installed packages
vcpkg update Display list of packages for updating
vcpkg upgrade Rebuild all outdated packages
vcpkg x-history (Experimental) Shows the history of CONTROL versions of a package
vcpkg hash [alg] Hash a file by specific algorithm, default SHA512
vcpkg help topics Display the list of help topics
vcpkg help Display help for a specific topic
vcpkg integrate install Make installed packages available user-wide. Requires admin
privileges on first use
vcpkg integrate remove Remove user-wide integration
vcpkg integrate project Generate a referencing nuget package for individual VS project use
vcpkg integrate powershell Enable PowerShell tab-completion
vcpkg export ... [opt]... Exports a package
vcpkg edit Open up a port for editing (uses %EDITOR%, default 'code')
vcpkg import Import a pre-built library
vcpkg create [archivename]
Create a new package
vcpkg owns Search for files in installed packages
vcpkg depend-info ... Display a list of dependencies for packages
vcpkg env Creates a clean shell environment for development or compiling
vcpkg version Display version information
vcpkg contact Display contact information to send feedback
...
>vcpkg search assimp
>vcpkg search | findstr assimp
assimp 5.0.1 The Open Asset import library
magnum-plugins[assimpimporter] AssimpImporter plugin
>vcpkg search | findstr glu
aws-sdk-cpp[glue] C++ SDK for the AWS glue service
freeglut 3.2.1-4 Open source implementation of GLUT with source and binary backwards compatibil...
glui 2019-11-30 GLUI is a GLUT-based C++ user interface library
mathgl[glut] glut module
>vcpkg install assimp:
Computing installation plan...
The following packages will be built and installed:
assimp[core]:x86-windows
* minizip[core]:x86-windows
* rapidjson[core]:x86-windows
* zlib[core]:x86-windows
Additional packages (*) will be modified to complete this operation.
Warning: The following VS instances are excluded because the English language pack is unavailable.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
Please install the English language pack.
安裝具有 Cuda 加速的 opencv 庫:
vcpkg search opencv
vcpkg install opencv[cuda]:x64-windows
vcpkg --triplet x64-windows install opencv[cuda]
支持的架構組合查詢:
>vcpkg help triplet
VCPKG built-in triplets
VCPKG community triplets
arm-uwp
arm-ios
arm64-windows
arm-mingw
x64-linux
arm-windows
x64-osx
arm64-ios
x64-uwp
arm64-mingw
x64-windows-static
arm64-uwp
x64-windows
arm64-windows-static
x86-windows
wasm32-emscripten
x64-ios
x64-mingw
x64-osx-dynamic
x64-windows-static-md
x86-ios
x86-mingw
x86-uwp
x86-windows-static-md
x86-windows-static
作為 MinGW 的用戶,我非愿意看到 triplet 列表中有 x64-mingw 和 x86-mingw 的身影。
可以設置默認的架構:
VCPKG_DEFAULT_TRIPLET=x64-windows
vcpkg 的 Triplet files 是用來記錄和庫相關的 OS、CPU、Compiler、Runtime 等信息的文件,它包含了編譯模塊時使用的工具鏈。
安裝第三方的 MinGW 架構依賴庫時出現錯誤:
>vcpkg install assimp:x64-mingw
Computing installation plan...
The following packages will be built and installed:
assimp[core]:x64-mingw
* minizip[core]:x64-mingw
* rapidjson[core]:x64-mingw
* zlib[core]:x64-mingw
Additional packages (*) will be modified to complete this operation.
Unable to determine toolchain to use for triplet x64-mingw with CMAKE_SYSTEM_NAME MinGW
提示信息表明,vcpkg 無法從 CMAKE_SYSTEM_NAME 指定的 x64-mingw 架構確定需要用到的工具鏈:
triplets/community/x64-mingw.cmake
這個問題有點惡心,因為 vcpkg 的源代碼忽略了 MinGW,解決方法是修改 build.cpp 重新編譯 vcpkg:
diff --git a/toolsrc/src/vcpkg/build.cpp b/toolsrc/src/vcpkg/build.cpp
index c61c6b7..d7c78aa 100644
--- a/toolsrc/src/vcpkg/build.cpp
+++ b/toolsrc/src/vcpkg/build.cpp
@@ -558,6 +558,10 @@ namespace vcpkg::Build
else if (cmake_system_name == "Android")
{
return m_paths.scripts / fs::u8path("toolchains/android.cmake");
+ }
+ else if (cmake_system_name == "MinGW")
+ {
+ return m_paths.scripts / fs::u8path("toolchains/mingw.cmake");
}
else if (cmake_system_name.empty() || cmake_system_name == "Windows" || cmake_system_name == "WindowsStore")
{
--
安裝好依賴模塊后,接著是將 vcpkg 集成到項目或進行全局集成:
>vcpkg integrate install
Applied user-wide integration for this vcpkg root.
All MSBuild C++ projects can now #include any installed libraries.
Linking will be handled automatically.
Installing new libraries will make them instantly available.
CMake projects should use: "-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake"
使用 CMake 的編譯項目中使用 vcpkg 安裝的庫,最佳方式指定 CMake (Toolchain File) 工具鏈文件 scripts/buildsystems/vcpkg.cmake,讓 find_package() 命令發現安裝的庫。
要使用這個文件,通過命令參數傳入 CMake 即可:
cmake .. -DCMAKE_TOOLCHAIN_FILE=vcpkg/scripts/buildsystems/vcpkg.cmake (Linux/MacOS)
cmake .. -DCMAKE_TOOLCHAIN_FILE=vcpkg\scripts\buildsystems\vcpkg.cmake (Windows)
再比如,如果要用 VS2017 編譯器,輸入下面命令即可:
cmake .. -DCMAKE_TOOLCHAIN_FILE=D:\vcpkg\scripts\buildsystems\vcpkg.cmake -G "Visual Studio 15 2017 Win64"
還有一種方法,直接在 CMakeLists.txt 文件中指定 CMAKE_TOOLCHAIN_FILE 變量,即:
set(CMAKE_TOOLCHAIN_FILE "D:\vcpkg\scripts\buildsystems\vcpkg.cmake")
project(PROJECT_NAME)
注意,要在 project() 命令之前設置。另外,類似 CMAKE_SYSTEM_NAME,CMAKE_C_COMPILER 等這些變量都要在 project()命令之前設定,不然 CMake 會按照默認的設置處理。
如果電腦中沒有安裝 cmake,vcpkg 會自動下載 cmake portable 版本。
集成安裝:
命令
說明
vcpkg integrate install
為所有用戶集成安裝依賴包
vcpkg integrate remove
為所有用戶移除集成安裝
vcpkg integrate project
為獨立 VS 項目創建 nuget 包引用
vcpkg integrate powershell
為 PowerShell Tab 自動完成集成
----------------------------
---------------------------------
依賴包的管理:
vcpkg.exe remove assimp
vcpkg.exe remove --outdated
vcpkg.exe list
vcpkg.exe export assimp --7zip
導出時必須指定導出的包格式。vcpkg支持5種導出包格式,有:
參數
格式
–raw
以不打包的目錄格式導出
–nuget
以 nuget 包形式導出
–ifw
基于 IFW 的安裝包
–zip
以 zip 壓縮包形式導出
–7zip
以 7z 壓縮包形式導出
總結
以上是生活随笔為你收集整理的vcpkg下载mysql库_VCpkg 开源库管理工具的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: JavaWeb框架梳理
 - 下一篇: 踩坑内核参数tcp_tw_recycle