如何使用(CMake Superbuild Boost Windows)正确下载Boost?

发布于 2025-02-08 05:46:24 字数 4249 浏览 3 评论 0原文

我正在尝试通过 externalProject_add 安装Boost,但我会遇到错误。

问题错误是什么意思,我该如何解决?

这是我拥有的错误消息:

 Performing update step for 'boost-external'
  No patch step for 'boost-external'
  Performing configure step for 'boost-external'
  'cp' is not recognized as an internal or external command,
  operable program or batch file.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Msbuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(241,5): e
rror MSB8066: Custom build for 'C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeFiles\7a303cde471
9f69085ebded4413f3304\boost-external-mkdir.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeF
iles\7a303cde4719f69085ebded4413f3304\boost-external-download.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02
_Boost\build\CMakeFiles\7a303cde4719f69085ebded4413f3304\boost-external-update.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super
_build\Example_02_Boost\build\CMakeFiles\7a303cde4719f69085ebded4413f3304\boost-external-patch.rule;C:\IBOIS57\_Code\Software
\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeFiles\7a303cde4719f69085ebded4413f3304\boost-external-configure.rule;C:\IB
OIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeFiles\7a303cde4719f69085ebded4413f3304\boost-external-
build.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeFiles\7a303cde4719f69085ebded4413f3304
\boost-external-install.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeFiles\1a2a6d9ea64ba5
92f97cd191c1d5acb1\boost-external-complete.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeF
iles\a70b522e33d20f4a0fb02fd1b3fdb173\boost-external.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\CM
akeLists.txt' exited with code 9009. [C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\boost-external.v
cxproj]

这是屏幕截图:

[![Enter Image Description在此处] [1]] [1] [1]:https://i.sstatic.net/hyrkm.jpg

这是我的完整cmakelists.txt

###############################################################################
#cmake + project name
###############################################################################
cmake_minimum_required(VERSION 3.10)
project(boostdemo)

###############################################################################
#create executable
###############################################################################
add_executable(boostdemo ${PROJECT_SOURCE_DIR}/main.cpp)

###############################################################################
#boost
###############################################################################
#https://github.com/BBO-repo/cpp-boost-cmake-superbuild
set( Boost_Bootstrap_Command ${CMAKE_BINARY_DIR}/boost-download/src/boost-external/bootstrap.sh && cp ${CMAKE_BINARY_DIR}/boost-download/src/boost-external-build/b2 ${CMAKE_BINARY_DIR}/boost-download/src/boost-external/)
set( Boost_b2_Command cd ${CMAKE_BINARY_DIR}/boost-download/src/boost-external && ./b2 )

include(ExternalProject)
ExternalProject_Add(
  boost-external #library name that will be used for linking in the executable
  GIT_REPOSITORY https://github.com/boostorg/boost.git
  GIT_TAG boost-1.79.0
  PREFIX boost-download
  CONFIGURE_COMMAND ${Boost_Bootstrap_Command}
  BUILD_COMMAND  ${Boost_b2_Command} install
    --without-python
    --without-mpi
    --disable-icu
    --prefix=${CMAKE_SOURCE_DIR}/thirdparty/boost/
    --threading=single,multi
    --link=shared
    --variant=release
    -j12
  INSTALL_COMMAND ""
)

set(Boost_LIBS ${CMAKE_SOURCE_DIR}/thirdparty/boost/lib/${CMAKE_STATIC_LIBRARY_PREFIX}boost_chrono${CMAKE_SHARED_LIBRARY_SUFFIX})
set(Boost_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/thirdparty/boost/include/)

###############################################################################
#link boost
###############################################################################

add_dependencies(boostdemo boost-external)
include_directories(boostdemo ${Boost_INCLUDE_DIR})
target_link_libraries(boostdemo ${Boost_LIBS})

I am trying to install boost by ExternalProject_Add but I get error.

Question What does the error mean and how can I resolve it?

This is the error message I have:

 Performing update step for 'boost-external'
  No patch step for 'boost-external'
  Performing configure step for 'boost-external'
  'cp' is not recognized as an internal or external command,
  operable program or batch file.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Msbuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(241,5): e
rror MSB8066: Custom build for 'C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeFiles\7a303cde471
9f69085ebded4413f3304\boost-external-mkdir.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeF
iles\7a303cde4719f69085ebded4413f3304\boost-external-download.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02
_Boost\build\CMakeFiles\7a303cde4719f69085ebded4413f3304\boost-external-update.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super
_build\Example_02_Boost\build\CMakeFiles\7a303cde4719f69085ebded4413f3304\boost-external-patch.rule;C:\IBOIS57\_Code\Software
\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeFiles\7a303cde4719f69085ebded4413f3304\boost-external-configure.rule;C:\IB
OIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeFiles\7a303cde4719f69085ebded4413f3304\boost-external-
build.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeFiles\7a303cde4719f69085ebded4413f3304
\boost-external-install.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeFiles\1a2a6d9ea64ba5
92f97cd191c1d5acb1\boost-external-complete.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\CMakeF
iles\a70b522e33d20f4a0fb02fd1b3fdb173\boost-external.rule;C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\CM
akeLists.txt' exited with code 9009. [C:\IBOIS57\_Code\Software\CPP\CMAKE\super_build\Example_02_Boost\build\boost-external.v
cxproj]

This is the screenshot:

[![enter image description here][1]][1]
[1]: https://i.sstatic.net/HyrKM.jpg

This is my full CMakeLists.txt

###############################################################################
#cmake + project name
###############################################################################
cmake_minimum_required(VERSION 3.10)
project(boostdemo)

###############################################################################
#create executable
###############################################################################
add_executable(boostdemo ${PROJECT_SOURCE_DIR}/main.cpp)

###############################################################################
#boost
###############################################################################
#https://github.com/BBO-repo/cpp-boost-cmake-superbuild
set( Boost_Bootstrap_Command ${CMAKE_BINARY_DIR}/boost-download/src/boost-external/bootstrap.sh && cp ${CMAKE_BINARY_DIR}/boost-download/src/boost-external-build/b2 ${CMAKE_BINARY_DIR}/boost-download/src/boost-external/)
set( Boost_b2_Command cd ${CMAKE_BINARY_DIR}/boost-download/src/boost-external && ./b2 )

include(ExternalProject)
ExternalProject_Add(
  boost-external #library name that will be used for linking in the executable
  GIT_REPOSITORY https://github.com/boostorg/boost.git
  GIT_TAG boost-1.79.0
  PREFIX boost-download
  CONFIGURE_COMMAND ${Boost_Bootstrap_Command}
  BUILD_COMMAND  ${Boost_b2_Command} install
    --without-python
    --without-mpi
    --disable-icu
    --prefix=${CMAKE_SOURCE_DIR}/thirdparty/boost/
    --threading=single,multi
    --link=shared
    --variant=release
    -j12
  INSTALL_COMMAND ""
)

set(Boost_LIBS ${CMAKE_SOURCE_DIR}/thirdparty/boost/lib/${CMAKE_STATIC_LIBRARY_PREFIX}boost_chrono${CMAKE_SHARED_LIBRARY_SUFFIX})
set(Boost_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/thirdparty/boost/include/)

###############################################################################
#link boost
###############################################################################

add_dependencies(boostdemo boost-external)
include_directories(boostdemo ${Boost_INCLUDE_DIR})
target_link_libraries(boostdemo ${Boost_LIBS})

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨落成白 2025-02-15 05:46:24

如果它可以帮助某人,下面是我用externalProject_add获得Boost的Cmake Fragment。当时我只专注于标头零件,因此可能还不完整。

我从来没有对此感到完全满意,最后转而使用VCPKG获得所有第三方依赖。从那以后,我一直很开心,尤其是在提升方面。实际上,我只是从我们的存储库中删除了此文件。因此,我强烈建议您查看VCPKG(或Conan或...),而不是externalproject_add

if(WIN32)
    set( Boost_Bootstrap_Command bootstrap.bat )
    set( Boost_b2_Command b2.exe )
    set( Boost_version_dir /boost-1_77 )
else()
    set( Boost_Bootstrap_Command ./bootstrap.sh )
    set( Boost_b2_Command ./b2 )
    set( Boost_version_dir "")
endif()

ExternalProject_Add(git_boost
    URL https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source/boost_1_77_0.tar.gz
    BUILD_IN_SOURCE 1
    CONFIGURE_COMMAND ${Boost_Bootstrap_Command}
    BUILD_COMMAND ""
    INSTALL_COMMAND ${Boost_b2_Command} --with-headers --with-math install --prefix=${CMAKE_CURRENT_BINARY_DIR}/boost
    TEST_COMMAND ""
)

add_library(ours_boost INTERFACE)
add_library(ours::boost ALIAS ours_boost)

target_include_directories(ours_boost INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/boost/include${Boost_version_dir})
message(${CMAKE_CURRENT_BINARY_DIR}/boost/include${Boost_version_dir})
add_dependencies(ours_boost git_boost)

In case it helps someone, below is the cmake fragment I used to have for obtaining boost with ExternalProject_Add. I was focussed at the time on the header only parts so it may not be complete.

I was never entirely happy with this and in the end switched to obtaining all of our third party dependencies with vcpkg. I have been much happier ever since, especially with regard to boost. In fact I just deleted this file from our repo. So I strongly recommend looking at vcpkg (or conan or ...) instead of ExternalProject_Add.

if(WIN32)
    set( Boost_Bootstrap_Command bootstrap.bat )
    set( Boost_b2_Command b2.exe )
    set( Boost_version_dir /boost-1_77 )
else()
    set( Boost_Bootstrap_Command ./bootstrap.sh )
    set( Boost_b2_Command ./b2 )
    set( Boost_version_dir "")
endif()

ExternalProject_Add(git_boost
    URL https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source/boost_1_77_0.tar.gz
    BUILD_IN_SOURCE 1
    CONFIGURE_COMMAND ${Boost_Bootstrap_Command}
    BUILD_COMMAND ""
    INSTALL_COMMAND ${Boost_b2_Command} --with-headers --with-math install --prefix=${CMAKE_CURRENT_BINARY_DIR}/boost
    TEST_COMMAND ""
)

add_library(ours_boost INTERFACE)
add_library(ours::boost ALIAS ours_boost)

target_include_directories(ours_boost INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/boost/include${Boost_version_dir})
message(${CMAKE_CURRENT_BINARY_DIR}/boost/include${Boost_version_dir})
add_dependencies(ours_boost git_boost)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文