小结
在Visual Studio 2019里使用CMake的工程碰到一些问题:
找不到Boost库
找不到OpenSSL库
进行了解决,并测试成功。
问题和解决
在Visual Studio 2019里使用CMake的工程可以参考微软的官方文档:
CMake projects in Visual Studio
找不到Boost库
比较觉的问题是找不到Boost的库文件,例如找不到libboost_regex-vc142-mt-gd-x64-1_70.lib
,大体上有以下一些解决办法:
编辑CmakeLists.txt文件
编辑CmakeLists.txt文件加入路径,例如:
SET(BOOST_LIBRARYDIR "C:/boost_1_70_0/stage/lib")
SET(BOOST_LIBRARY_DIR "C:/boost_1_70_0/stage/lib")
SET(BOOST_INCLUDEDIR "C:/boost_1_70_0")
SET(BOOST_INCLUDE_DIR "C:/boost_1_70_0")
set(BOOST_ROOT "C:/boost_1_70_0")
SET(BOOST_lib "C:/boost_1_70_0/stage/lib")
以下设置可以解决很多问题:
add_definitions( -DBOOST_ALL_NO_LIB )
add_definitions( -DBOOST_SYSTEM_NO_DEPRECATED )
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_DEBUG ON)
设置Visual Studio 2019
在Visual Studio 2019中Project
–> CMake Settings for 'Your Porject Name'
可以进行各种Cmake Settings
在Cmake command arguments
加入:
-DBoost_DEBUG=ON -DBOOST_INCLUDEDIR="C:/boost_1_70_0/libs" -DBOOST_LIBRARYDIR="C:/boost_1_70_0/stage/lib"
设置Windows环境变量
可以设置一些Windows的环境变量,如下:
Environment Vairables
–> System variables
添加:
BOOST_INCLUDEDIR –> C:\boost_1_70_0\libs
BOOST_LIBRARYDIR –> C:\boost_1_70_0\stage\lib
BOOST_ROOT –> C:\ROS\boost_1_70_0
或者添加到Path
环境变量中。
找不到OpenSSL库
OpenSSL下载源码需要编译,这里直接安装OpenSSL,下载并安装 了Win64OpenSSL-3_0_5.msi
。
Environment Vairables
–> System variables
添加:
OPENSSL_CRYPTO_LIBRARY –> C:\Program Files\OpenSSL-Win64\lib
OPENSSL_INCLUDE_DIR –> C:\Program Files\OpenSSL-Win64\include
OPENSSL_LIBRARIES –> C:\Program Files\OpenSSL-Win64\lib
OPENSSL_ROOT_DIR –> C:\Program Files\OpenSSL-Win64
参考
Failed linking to boost library with CMake generated project file for MSVC9
Windows OpenSSL Could NOT find OpenSSL解决方案
Win32/Win64 OpenSSL: https://slproweb.com/products/Win32OpenSSL.html
CMake not able to find OpenSSL library
cmake Could NOT find Boost (missing: xxx 的问题解决
CMake unable to load boost 1.78.0 components in visual studio 2019
https://docs.microsoft.com/: CMake projects in Visual Studio