从Visual Studio 2022内运行时CMake无法检测到编译器

hc2pp10m  于 2022-12-23  发布在  其他
关注(0)|答案(1)|浏览(656)

安装VS 2022并下载和编译boost 1.82后,我尝试运行一个测试项目,一个应该跨平台编译的项目(VS 2022中的新功能,或者以前版本中也有这个功能??)。我在VS中创建了一个新的VC++项目和解决方案,方法是文件〉新建〉项目〉CMake项目。
将CMakeLists.txt文件修改为:

...
set (BOOST_ROOT "C:/boost/boost")
set (BOOST_INCLUDEDIR "C:/boost/boost/include")
set (BOOST_LIBRARYDIR "C:/boost/boost/stage/lib")
set (BOOST_MIN_VERSION "1.82.0")
set(Boost_USE_STATIC_LIBS ON) 
set(Boost_USE_MULTITHREADED ON)  
set(Boost_USE_STATIC_RUNTIME OFF) 
set(Boost_DEBUG ON)
find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS date_time REQUIRED)
if (NOT Boost_FOUND)
  message(FATAL_ERROR "Fatal error: Boost (version >= ${BOOST_MIN_VERSION}) required.")
endif()
include_directories(${Boost_INCLUDE_DIRS}) 
link_directories(${Boost_LIBRARY_DIRS})
...

然后执行项目〉删除缓存并重新配置
问题是它无法找到boost库,我相信这是因为它无法弄清楚编译器是什么:

....
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1862 ] Boost_VERSION_MAJOR = "1"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1863 ] Boost_VERSION_MINOR = "82"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1864 ] Boost_VERSION_PATCH = "0"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1865 ] Boost_VERSION_COUNT = "3"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1889 ] Boost_LIB_PREFIX = ""
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1890 ] Boost_NAMESPACE = "boost"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:953 ] _boost_COMPILER = "" (guessed)
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1926 ] _boost_MULTITHREADED = "-mt"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:2004 ] _boost_ARCHITECTURE_TAG = "" (detected)
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:2008 ] _boost_RELEASE_ABI_TAG = "-"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:2009 ] _boost_DEBUG_ABI_TAG = "-d"
....

此处,检测到_boost_编译器为_boost_COMPILER = "" (guessed)
你知道这里可能出了什么问题吗?VS应该正确地告诉CMake它自己,因为我是从它内部调用CMake的?
编辑:附加CMake的整个输出

1> CMake generation started for default configuration: 'x64-Debug'.
1> Command line: "C:\WINDOWS\system32\cmd.exe" /c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\Microsoft\CMake\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\johns\source\repos\LogMon\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe"  -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\Microsoft\CMake\Ninja\ninja.exe" "C:\Users\johns\source\repos\LogMon" 2>&1"
1> Working directory: C:\Users\johns\source\repos\LogMon\out\build\x64-Debug
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1689 ] _boost_TEST_VERSIONS = <unset>
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1690 ] Boost_USE_MULTITHREADED = "ON"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1691 ] Boost_USE_STATIC_LIBS = "ON"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1692 ] Boost_USE_STATIC_RUNTIME = "OFF"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1693 ] Boost_ADDITIONAL_VERSIONS = <unset>
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1694 ] Boost_NO_SYSTEM_PATHS = <unset>
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1726 ] BOOST_ROOT = "C:/boost/boost"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1727 ] ENV{BOOST_ROOT} = <unset>
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1728 ] BOOST_INCLUDEDIR = "C:/boost/boost/include"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1729 ] ENV{BOOST_INCLUDEDIR} = <unset>
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1730 ] BOOST_LIBRARYDIR = "C:/boost/boost/stage/lib"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1731 ] ENV{BOOST_LIBRARYDIR} = <unset>
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1803 ] _boost_INCLUDE_SEARCH_DIRS = "C:/boost/boost/include;C:/boost/boost/include;C:/boost/boost;PATHS;C:/boost/include;C:/boost;/sw/local/include"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1804 ] _boost_PATH_SUFFIXES = <unset>
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1819 ] location of version.hpp: C:/boost/boost/boost/version.hpp
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1859 ] Boost_VERSION = "108200"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1860 ] Boost_VERSION_STRING = "1.82.0"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1861 ] Boost_VERSION_MACRO = "108200"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1862 ] Boost_VERSION_MAJOR = "1"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1863 ] Boost_VERSION_MINOR = "82"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1864 ] Boost_VERSION_PATCH = "0"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1865 ] Boost_VERSION_COUNT = "3"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1889 ] Boost_LIB_PREFIX = "lib"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1890 ] Boost_NAMESPACE = "boost"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:953 ] _boost_COMPILER = "" (guessed)
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1926 ] _boost_MULTITHREADED = "-mt"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:2004 ] _boost_ARCHITECTURE_TAG = "" (detected)
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:2008 ] _boost_RELEASE_ABI_TAG = "-"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:2009 ] _boost_DEBUG_ABI_TAG = "-d"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:2069 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = "C:/boost/boost/stage/lib;C:/boost/boost/lib;C:/boost/boost/stage/lib;C:/boost/boost/lib;C:/boost/boost/../lib;C:/boost/boost/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib"
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:2070 ] _boost_LIBRARY_SEARCH_DIRS_DEBUG = "C:/boost/boost/stage/lib;C:/boost/boost/lib;C:/boost/boost/stage/lib;C:/boost/boost/lib;C:/boost/boost/../lib;C:/boost/boost/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib"
1> [CMake] CMake Warning at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1384 (message):
1> [CMake]   New Boost version may have incorrect or missing dependencies and imported
1> [CMake]   targets
1> [CMake] Call Stack (most recent call first):
1> [CMake]   C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:1507 (_Boost_COMPONENT_DEPENDENCIES)
1> [CMake]   C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:2118 (_Boost_MISSING_DEPENDENCIES)
1> [CMake]   CMakeLists.txt:14 (find_package)
1> [CMake] 
1> [CMake] 
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:2255 ] Searching for DATE_TIME_LIBRARY_RELEASE: libboost_date_time-mt-1_82;libboost_date_time-mt;libboost_date_time-mt;libboost_date_time-mt;libboost_date_time
1> [CMake] -- [ C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:2310 ] Searching for DATE_TIME_LIBRARY_DEBUG: libboost_date_time-mt-d-1_82;libboost_date_time-mt-d;libboost_date_time-mt-d;libboost_date_time-mt;libboost_date_time
1> [CMake] CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
1> [CMake]   Could NOT find Boost (missing: date_time) (found suitable version "1.82.0",
1> [CMake]   minimum required is "1.82.0")
1> [CMake] Call Stack (most recent call first):
1> [CMake]   C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
1> [CMake]   C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.24/Modules/FindBoost.cmake:2376 (find_package_handle_standard_args)
1> [CMake]   CMakeLists.txt:14 (find_package)
1> [CMake] -- Configuring incomplete, errors occurred!
1> 'C:\WINDOWS\system32\cmd.exe' '/c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\Microsoft\CMake\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\johns\source\repos\LogMon\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe"  -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\Microsoft\CMake\Ninja\ninja.exe" "C:\Users\johns\source\repos\LogMon" 2>&1"' execution failed with error: ''C:\WINDOWS\system32\cmd.exe' '/c "%SYSTEMROOT%\System32\chcp.com 65001 >NUL && "C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\Microsoft\CMake\CMake\bin\cmake.exe"  -G "Ninja"  -DCMAKE_BUILD_TYPE:STRING="Debug" -DCMAKE_INSTALL_PREFIX:PATH="C:\Users\johns\source\repos\LogMon\out\install\x64-Debug" -DCMAKE_C_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe" -DCMAKE_CXX_COMPILER:FILEPATH="C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe"  -DCMAKE_MAKE_PROGRAM="C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\Microsoft\CMake\Ninja\ninja.exe" "C:\Users\johns\source\repos\LogMon" 2>&1"' returned with exit code: 1'.
hs1ihplo

hs1ihplo1#

在浏览了整个日志后,问题似乎超出了您的预期。

...
find_package(Boost ${BOOST_MIN_VERSION} COMPONENTS date_time REQUIRED) #<---
...

日志的底部是这样写的:

#Missing date_time... i.e. it can't find a REQUIRED component
1> [CMake]   Could NOT find Boost (missing: date_time) (found suitable version "1.82.0",
1> [CMake]   minimum required is "1.82.0")

要正确调试此问题,我建议在此处检查这些变量输出的路径:

1> [...] _boost_LIBRARY_SEARCH_DIRS_RELEASE = "C:/boost/boost/stage/lib;C:/boost/boost/lib;C:/boost/boost/stage/lib;C:/boost/boost/lib;C:/boost/boost/../lib;C:/boost/boost/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib"
1> [...] _boost_LIBRARY_SEARCH_DIRS_DEBUG = "C:/boost/boost/stage/lib;C:/boost/boost/lib;C:/boost/boost/stage/lib;C:/boost/boost/lib;C:/boost/boost/../lib;C:/boost/boost/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib"

并仔细检查这些库是否存在于目录中(它们可能不会)

1> [...] Searching for DATE_TIME_LIBRARY_RELEASE: libboost_date_time-mt-1_82;libboost_date_time-mt;libboost_date_time-mt;libboost_date_time-mt;libboost_date_time
1> [...] Searching for DATE_TIME_LIBRARY_DEBUG: libboost_date_time-mt-d-1_82;libboost_date_time-mt-d;libboost_date_time-mt-d;libboost_date_time-mt;libboost_date_time

然后我会检查这些库是否存在于boost文件夹中,很有可能它们不存在,这很可能是因为它们要么是不同组件的一部分,要么只是在boost安装中丢失了。
尝试包括整个升压,看看是否是这种情况:

find_package(Boost ${BOOST_MIN_VERSION})

希望能有所帮助!
编辑:我已经设法复制了你的问题,这很可能是由于未检测到的编译器。当构建boost时,它会将编译器作为后缀(或中间名)附加到库中。也就是说,如果你检查lib目录,你可以推断出使用的是哪个编译器,也许可以通过set(Boost_COMPILER "-vcXYZ")强制设置变量。
请注意,由于这个未设置的变量,libboost_date_time-mt-d-1_82缺少编译器。它应该看起来像libboost_date_time-vc142-mt-d-1_82(如果你用vc142编译)

相关问题