简体   繁体   English

如何在 C++ 项目中将 Boost 作为 Git 子模块包含在 CMake 项目中?

[英]How to include Boost in a C++ project as a Git submodule in a CMake project?

I am trying to compile a CMake project but keep getting complaints about "Could not find Boost".我正在尝试编译一个 CMake 项目,但不断收到关于“找不到 Boost”的抱怨。 I've tried setting BOOST_ROOT as well and doing find_package instead.我也尝试过设置 BOOST_ROOT 并改为使用find_package Oddly enough, I'm pretty sure this works on Mac but not Windows?奇怪的是,我很确定这适用于 Mac 而不是 Windows?

Project layout (external git submodules live in deps/):项目布局(外部 git 子模块位于 deps/ 中):

>dir
 Volume in drive C has no label.
 Volume Serial Number is 8235-910C

 Directory of C:\Users\Brandon\Desktop\redis-j2534-rpc

11/05/2021  12:06 AM    <DIR>          .
11/05/2021  12:06 AM    <DIR>          ..
11/04/2021  11:21 PM                22 .gitignore
11/04/2021  11:21 PM               825 .gitmodules
11/05/2021  12:28 AM             1,318 CMakeLists.txt
11/04/2021  11:21 PM    <DIR>          deps
11/04/2021  11:21 PM             1,176 README.md
11/04/2021  11:21 PM    <DIR>          src
11/05/2021  12:28 AM    <DIR>          Win32
               4 File(s)          3,341 bytes
               5 Dir(s)  274,146,738,176 bytes free

Proof deps is populated:证明 deps 已填充:

>dir deps
 Volume in drive C has no label.
 Volume Serial Number is 8235-910C

 Directory of C:\Users\Brandon\Desktop\redis-j2534-rpc\deps

11/04/2021  11:21 PM    <DIR>          .
11/04/2021  11:21 PM    <DIR>          ..
11/04/2021  11:26 PM    <DIR>          boost
11/04/2021  11:54 PM    <DIR>          dlfcn-win32
11/04/2021  11:54 PM    <DIR>          hiredis
11/04/2021  11:54 PM    <DIR>          libconfig
11/04/2021  11:54 PM    <DIR>          msgpack-c
               0 File(s)              0 bytes
               7 Dir(s)  274,135,240,704 bytes free

CMakeLists.txt: CMakeLists.txt:

cmake_minimum_required(VERSION 3.5.1)
project(redis-rpc)
set(CMAKE_CXX_STANDARD 11)
#set(CMAKE_OSX_ARCHITECTURES "x86_64")
# variables
set(BUILD_SHARED_LIBS OFF CACHE BOOL "")
set(BUILD_TESTS OFF CACHE BOOL "")
set(DISABLE_TESTS ON CACHE BOOL "")
set(BUILD_EXAMPLES OFF CACHE BOOL "")
# dependencies
add_subdirectory("deps/boost")
add_subdirectory("deps/dlfcn-win32")
add_subdirectory("deps/libconfig")
add_subdirectory("deps/hiredis")
add_subdirectory("deps/msgpack-c")
include_directories("deps/msgpack-c/include")
include_directories("deps/libconfig/lib")

# vehicle
add_executable(
  vehicle
  src/vehicle.cc
  src/redis.cc
  src/convert.cc
)
target_link_libraries(
  vehicle
  hiredis
  msgpackc-cxx
  config
  #libconfig
  #shlwapi
  dl
)
# tester
add_library(
  tester
  SHARED
  src/tester.cc
  src/redis.cc
  src/convert.cc
)
target_link_libraries(
  tester
  hiredis
  msgpackc-cxx
  config
  #libconfig
  #shlwapi
  dl
)

Error:错误:

cmake -A Win32 -S . -B "Win32" && cmake --build Win32 --config Debug
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19042.
-- Boost: static libraries, shared runtime, MPI OFF, Python OFF, testing OFF
-- Boost.Context: architecture i386, binary format pe, ABI ms, assembler masm, suffix .asm, implementation fcontext
-- Boost.Fiber: NUMA target OS is windows
-- Boost.Iostreams: ZLIB OFF, BZip2 OFF, LZMA OFF, Zstd OFF
-- Boost.Locale: iconv OFF, ICU OFF, POSIX OFF, std ON, winapi ON
-- Boost.Log: Message compiler mc.exe not found, event log support will be disabled.
-- Boost.Math: standalone mode OFF
-- Boost.Stacktrace: noop ON, backtrace OFF, addr2line OFF, basic ON, windbg ON, windbg_cached ON
-- Boost.Thread: threading API is win32
Detected version: 1.0.3
-- Dynamically linking with Boost
CMake Error at C:/Program Files/CMake/share/cmake-3.21/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Boost (missing: Boost_INCLUDE_DIR)
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.21/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files/CMake/share/cmake-3.21/Modules/FindBoost.cmake:2360 (find_package_handle_standard_args)
  deps/msgpack-c/CMakeLists.txt:103 (FIND_PACKAGE)


-- Configuring incomplete, errors occurred!
See also "C:/Users/Brandon/Desktop/redis-j2534-rpc/Win32/CMakeFiles/CMakeOutput.log".

msgpack-c didn't like add_subdirectory("deps/boost-cmake") msgpack-c不喜欢add_subdirectory("deps/boost-cmake")

It needed a manual set(Boost_INCLUDE_DIR "C:/Users/Brandon/Desktop/project/Win32/_deps/boost-src")它需要一个手动set(Boost_INCLUDE_DIR "C:/Users/Brandon/Desktop/project/Win32/_deps/boost-src")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM