c++ - CMake 未使用 brew (macOS) 找到 boost_python 库

标签 c++ macos boost cmake

我觉得我快疯了。出于某种奇怪的原因,我无法让 cmake 找到 boost_python。我一直使用相同的 CMakeList 和相同的步骤在 macOS 上安装具有 Boost-Python 支持的 Boost。在 GNU/Linux 和 Windows 上,我通常只是手动构建库并且它工作得很好。几个月前,通过发出以下命令,它在 macOS 上也能完美运行:

brew install python2 boost boost-python

(我专门使用 python2 而不是 python3)

我不知道是什么导致了这个问题,因为我以前从未遇到过...也许它无法从 brew 中找到 boost-python 库? (/usr/local/Cellar/boost-python/1.67.0/lib/)。但话又说回来,我从来没有为 cmake 或类似的东西改变搜索路径而烦恼。此 CMakeList 在 Linux 和 macOS 下始终有效。

我的 CMakeList.txt

cmake_minimum_required(VERSION 3.6)
project(game-client)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-std=c++1z -Wall -Wextra -Wno-unused-parameter -pthread")

# configure boost
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)

find_package(Boost COMPONENTS filesystem system python REQUIRED)
if (NOT Boost_FOUND)
  MESSAGE(FATAL_ERROR "Could not find boost library")
endif ()

# configure python
find_package(PythonLibs 2.7 REQUIRED)
if (NOT PYTHONLIBS_FOUND)
  MESSAGE(FATAL_ERROR "Could not find python library")
endif ()

include_directories(${Boost_INCLUDE_DIRS})
include_directories(${PYTHON_INCLUDE_DIRS})

# configure preprocessor flags for internal classlogs
add_definitions(-DDUMP_GOOD_PACKETS)
# add_definitions(-DCLASSLOG)

set(SOURCE_FILES src/main.cpp src/Config.cpp include/Config.hpp     src/SequenceTable.cpp include/SequenceTable.hpp
        include/Singleton.hpp include/Logger.hpp src/NetworkStream.cpp include/NetworkStream.hpp
    include/packets/incoming/in.hpp include/packets/outcoming/out.hpp src/Buffer.cpp include/Buffer.hpp
    include/Packet.hpp src/PacketHandler.cpp include/PacketHandler.hpp src/Core.cpp
    include/Core.hpp src/Cipher.cpp include/Cipher.hpp src/KeyAgreement.cpp include/KeyAgreement.hpp
    src/AuthInput.cpp include/AuthInput.hpp src/MainInput.cpp include/MainInput.hpp include/PythonManager.hpp
    src/PythonManager.cpp include/PythonInstance.hpp src/PythonInstance.cpp include/packets/common/common.hpp
    src/Entity.cpp include/Entity.hpp include/Item.hpp src/Item.cpp src/Environment.cpp include/Environment.hpp)
add_executable(game-client ${SOURCE_FILES})
target_link_libraries(game-client ${Boost_LIBRARIES} ${PYTHON_LIBRARIES}     cryptopp)

cmake 输出:

memcpys-MBP:build memcpy$ cmake ..
-- The C compiler identification is Clang 6.0.0
-- The CXX compiler identification is Clang 6.0.0
-- Check for working C compiler: /usr/local/opt/llvm/bin/clang
-- Check for working C compiler: /usr/local/opt/llvm/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++ --     works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at     /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:2044     (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.67.0

  Boost include path: /usr/local/include

  Could not find the following static Boost libraries:

          boost_python

  Some (but not all) of the required Boost libraries were found.  You may
  need to install these additional Boost libraries.  Alternatively, set
  BOOST_LIBRARYDIR to the directory containing Boost libraries or     BOOST_ROOT
  to the location of Boost.
Call Stack (most recent call first):
  CMakeLists.txt:10 (find_package)


CMake Error at CMakeLists.txt:12 (MESSAGE):
  Could not find boost library


-- Configuring incomplete, errors occurred!
See also "/Users/memcpy/git-repos/game-    client/build/CMakeFiles/CMakeOutput.log".

我按照评论中的建议使用以下选项运行 cmake:

cmake -DBoost_DEBUG=ON ..

-- The C compiler identification is Clang 6.0.0
-- The CXX compiler identification is Clang 6.0.0
-- Check for working C compiler: /usr/local/opt/llvm/bin/clang
-- Check for working C compiler: /usr/local/opt/llvm/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1121 ] _boost_TEST_VERSIONS = 1.67.0;1.67;1.66.0;1.66;1.65.1;1.65.0;1.65;1.64.0;1.64;1.63.0;1.63;1.62.0;1.62;1.61.0;1.61;1.60.0;1.60;1.59.0;1.59;1.58.0;1.58;1.57.0;1.57;1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53;1.52.0;1.52;1.51.0;1.51;1.50.0;1.50;1.49.0;1.49;1.48.0;1.48;1.47.0;1.47;1.46.1;1.46.0;1.46;1.45.0;1.45;1.44.0;1.44;1.43.0;1.43;1.42.0;1.42;1.41.0;1.41;1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1123 ] Boost_USE_MULTITHREADED = ON
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1125 ] Boost_USE_STATIC_LIBS = ON
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1127 ] Boost_USE_STATIC_RUNTIME = 
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1129 ] Boost_ADDITIONAL_VERSIONS = 
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1131 ] Boost_NO_SYSTEM_PATHS = 
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1199 ] Declared as CMake or Environmental Variables:
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1201 ]   BOOST_ROOT = 
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1203 ]   BOOST_INCLUDEDIR = 
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1205 ]   BOOST_LIBRARYDIR = 
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1207 ] _boost_TEST_VERSIONS = 1.67.0;1.67;1.66.0;1.66;1.65.1;1.65.0;1.65;1.64.0;1.64;1.63.0;1.63;1.62.0;1.62;1.61.0;1.61;1.60.0;1.60;1.59.0;1.59;1.58.0;1.58;1.57.0;1.57;1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53;1.52.0;1.52;1.51.0;1.51;1.50.0;1.50;1.49.0;1.49;1.48.0;1.48;1.47.0;1.47;1.46.1;1.46.0;1.46;1.45.0;1.45;1.44.0;1.44;1.43.0;1.43;1.42.0;1.42;1.41.0;1.41;1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1282 ] Include debugging info:
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1284 ]   _boost_INCLUDE_SEARCH_DIRS = PATHS;C:/boost/include;C:/boost;/sw/local/include
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1286 ]   _boost_PATH_SUFFIXES = boost-1_67_0;boost_1_67_0;boost/boost-1_67_0;boost/boost_1_67_0;boost-1_67;boost_1_67;boost/boost-1_67;boost/boost_1_67;boost-1_66_0;boost_1_66_0;boost/boost-1_66_0;boost/boost_1_66_0;boost-1_66;boost_1_66;boost/boost-1_66;boost/boost_1_66;boost-1_65_1;boost_1_65_1;boost/boost-1_65_1;boost/boost_1_65_1;boost-1_65_0;boost_1_65_0;boost/boost-1_65_0;boost/boost_1_65_0;boost-1_65;boost_1_65;boost/boost-1_65;boost/boost_1_65;boost-1_64_0;boost_1_64_0;boost/boost-1_64_0;boost/boost_1_64_0;boost-1_64;boost_1_64;boost/boost-1_64;boost/boost_1_64;boost-1_63_0;boost_1_63_0;boost/boost-1_63_0;boost/boost_1_63_0;boost-1_63;boost_1_63;boost/boost-1_63;boost/boost_1_63;boost-1_62_0;boost_1_62_0;boost/boost-1_62_0;boost/boost_1_62_0;boost-1_62;boost_1_62;boost/boost-1_62;boost/boost_1_62;boost-1_61_0;boost_1_61_0;boost/boost-1_61_0;boost/boost_1_61_0;boost-1_61;boost_1_61;boost/boost-1_61;boost/boost_1_61;boost-1_60_0;boost_1_60_0;boost/boost-1_60_0;boost/boost_1_60_0;boost-1_60;boost_1_60;boost/boost-1_60;boost/boost_1_60;boost-1_59_0;boost_1_59_0;boost/boost-1_59_0;boost/boost_1_59_0;boost-1_59;boost_1_59;boost/boost-1_59;boost/boost_1_59;boost-1_58_0;boost_1_58_0;boost/boost-1_58_0;boost/boost_1_58_0;boost-1_58;boost_1_58;boost/boost-1_58;boost/boost_1_58;boost-1_57_0;boost_1_57_0;boost/boost-1_57_0;boost/boost_1_57_0;boost-1_57;boost_1_57;boost/boost-1_57;boost/boost_1_57;boost-1_56_0;boost_1_56_0;boost/boost-1_56_0;boost/boost_1_56_0;boost-1_56;boost_1_56;boost/boost-1_56;boost/boost_1_56;boost-1_55_0;boost_1_55_0;boost/boost-1_55_0;boost/boost_1_55_0;boost-1_55;boost_1_55;boost/boost-1_55;boost/boost_1_55;boost-1_54_0;boost_1_54_0;boost/boost-1_54_0;boost/boost_1_54_0;boost-1_54;boost_1_54;boost/boost-1_54;boost/boost_1_54;boost-1_53_0;boost_1_53_0;boost/boost-1_53_0;boost/boost_1_53_0;boost-1_53;boost_1_53;boost/boost-1_53;boost/boost_1_53;boost-1_52_0;boost_1_52_0;boost/boost-1_52_0;boost/boost_1_52_0;boost-1_52;boost_1_52;boost/boost-1_52;boost/boost_1_52;boost-1_51_0;boost_1_51_0;boost/boost-1_51_0;boost/boost_1_51_0;boost-1_51;boost_1_51;boost/boost-1_51;boost/boost_1_51;boost-1_50_0;boost_1_50_0;boost/boost-1_50_0;boost/boost_1_50_0;boost-1_50;boost_1_50;boost/boost-1_50;boost/boost_1_50;boost-1_49_0;boost_1_49_0;boost/boost-1_49_0;boost/boost_1_49_0;boost-1_49;boost_1_49;boost/boost-1_49;boost/boost_1_49;boost-1_48_0;boost_1_48_0;boost/boost-1_48_0;boost/boost_1_48_0;boost-1_48;boost_1_48;boost/boost-1_48;boost/boost_1_48;boost-1_47_0;boost_1_47_0;boost/boost-1_47_0;boost/boost_1_47_0;boost-1_47;boost_1_47;boost/boost-1_47;boost/boost_1_47;boost-1_46_1;boost_1_46_1;boost/boost-1_46_1;boost/boost_1_46_1;boost-1_46_0;boost_1_46_0;boost/boost-1_46_0;boost/boost_1_46_0;boost-1_46;boost_1_46;boost/boost-1_46;boost/boost_1_46;boost-1_45_0;boost_1_45_0;boost/boost-1_45_0;boost/boost_1_45_0;boost-1_45;boost_1_45;boost/boost-1_45;boost/boost_1_45;boost-1_44_0;boost_1_44_0;boost/boost-1_44_0;boost/boost_1_44_0;boost-1_44;boost_1_44;boost/boost-1_44;boost/boost_1_44;boost-1_43_0;boost_1_43_0;boost/boost-1_43_0;boost/boost_1_43_0;boost-1_43;boost_1_43;boost/boost-1_43;boost/boost_1_43;boost-1_42_0;boost_1_42_0;boost/boost-1_42_0;boost/boost_1_42_0;boost-1_42;boost_1_42;boost/boost-1_42;boost/boost_1_42;boost-1_41_0;boost_1_41_0;boost/boost-1_41_0;boost/boost_1_41_0;boost-1_41;boost_1_41;boost/boost-1_41;boost/boost_1_41;boost-1_40_0;boost_1_40_0;boost/boost-1_40_0;boost/boost_1_40_0;boost-1_40;boost_1_40;boost/boost-1_40;boost/boost_1_40;boost-1_39_0;boost_1_39_0;boost/boost-1_39_0;boost/boost_1_39_0;boost-1_39;boost_1_39;boost/boost-1_39;boost/boost_1_39;boost-1_38_0;boost_1_38_0;boost/boost-1_38_0;boost/boost_1_38_0;boost-1_38;boost_1_38;boost/boost-1_38;boost/boost_1_38;boost-1_37_0;boost_1_37_0;boost/boost-1_37_0;boost/boost_1_37_0;boost-1_37;boost_1_37;boost/boost-1_37;boost/boost_1_37;boost-1_36_1;boost_1_36_1;boost/boost-1_36_1;boost/boost_1_36_1;boost-1_36_0;boost_1_36_0;boost/boost-1_36_0;boost/boost_1_36_0;boost-1_36;boost_1_36;boost/boost-1_36;boost/boost_1_36;boost-1_35_1;boost_1_35_1;boost/boost-1_35_1;boost/boost_1_35_1;boost-1_35_0;boost_1_35_0;boost/boost-1_35_0;boost/boost_1_35_0;boost-1_35;boost_1_35;boost/boost-1_35;boost/boost_1_35;boost-1_34_1;boost_1_34_1;boost/boost-1_34_1;boost/boost_1_34_1;boost-1_34_0;boost_1_34_0;boost/boost-1_34_0;boost/boost_1_34_0;boost-1_34;boost_1_34;boost/boost-1_34;boost/boost_1_34;boost-1_33_1;boost_1_33_1;boost/boost-1_33_1;boost/boost_1_33_1;boost-1_33_0;boost_1_33_0;boost/boost-1_33_0;boost/boost_1_33_0;boost-1_33;boost_1_33;boost/boost-1_33;boost/boost_1_33
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1306 ] location of version.hpp: /usr/local/include/boost/version.hpp
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1330 ] version.hpp reveals boost 1.67.0
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1416 ] guessed _boost_COMPILER = 
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1426 ] _boost_MULTITHREADED = -mt
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1502 ] _boost_RELEASE_ABI_TAG = -
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1504 ] _boost_DEBUG_ABI_TAG = -d
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1567 ] _boost_LIBRARY_SEARCH_DIRS_RELEASE = /usr/local/include/lib;/usr/local/include/../lib;/usr/local/include/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib_boost_LIBRARY_SEARCH_DIRS_DEBUG   = /usr/local/include/lib;/usr/local/include/../lib;/usr/local/include/stage/lib;PATHS;C:/boost/lib;C:/boost;/sw/local/lib
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1756 ] Searching for FILESYSTEM_LIBRARY_RELEASE: boost_filesystem-mt-1_67;boost_filesystem-mt;boost_filesystem
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:400 ]  Boost_LIBRARY_DIR_RELEASE = /usr/local/lib _boost_LIBRARY_SEARCH_DIRS_RELEASE = /usr/local/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1809 ] Searching for FILESYSTEM_LIBRARY_DEBUG: boost_filesystem-mt-d-1_67;boost_filesystem-mt-d;boost_filesystem-mt;boost_filesystem
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:400 ]  Boost_LIBRARY_DIR_DEBUG = /usr/local/lib _boost_LIBRARY_SEARCH_DIRS_DEBUG = /usr/local/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1756 ] Searching for SYSTEM_LIBRARY_RELEASE: boost_system-mt-1_67;boost_system-mt;boost_system
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:400 ]  Boost_LIBRARY_DIR_RELEASE = /usr/local/lib _boost_LIBRARY_SEARCH_DIRS_RELEASE = /usr/local/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1809 ] Searching for SYSTEM_LIBRARY_DEBUG: boost_system-mt-d-1_67;boost_system-mt-d;boost_system-mt;boost_system
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:400 ]  Boost_LIBRARY_DIR_DEBUG = /usr/local/lib _boost_LIBRARY_SEARCH_DIRS_DEBUG = /usr/local/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1756 ] Searching for PYTHON_LIBRARY_RELEASE: boost_python-mt-1_67;boost_python-mt;boost_python
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:400 ]  Boost_LIBRARY_DIR_RELEASE = /usr/local/lib _boost_LIBRARY_SEARCH_DIRS_RELEASE = /usr/local/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1809 ] Searching for PYTHON_LIBRARY_DEBUG: boost_python-mt-d-1_67;boost_python-mt-d;boost_python-mt;boost_python
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:400 ]  Boost_LIBRARY_DIR_DEBUG = /usr/local/lib _boost_LIBRARY_SEARCH_DIRS_DEBUG = /usr/local/lib;NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH
-- [ /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:1883 ] Boost_FOUND = 1
CMake Error at /usr/local/Cellar/cmake/3.11.4/share/cmake/Modules/FindBoost.cmake:2044 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.67.0

  Boost include path: /usr/local/include

  Could not find the following static Boost libraries:

          boost_python

  Some (but not all) of the required Boost libraries were found.  You may
  need to install these additional Boost libraries.  Alternatively, set
  BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
  to the location of Boost.
Call Stack (most recent call first):
  CMakeLists.txt:10 (find_package)


CMake Error at CMakeLists.txt:12 (MESSAGE):
  Could not find boost library


-- Configuring incomplete, errors occurred!
See also "/Users/memcpy/git-repos/game-client/build/CMakeFiles/CMakeOutput.log".

最佳答案

@Tsyvarev 这个。我需要将组件更改为“python27”。随着时间的推移,这种行为肯定发生了变化。我不记得必须在 boost 版本 >= 1.65 <= 1.67 时执行此操作。谢谢。

关于c++ - CMake 未使用 brew (macOS) 找到 boost_python 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50919160/

相关文章:

c++ - 有了模板,如何区分两种并列的情况,比如浮点型和整数型?

c++ - 按字符循环遍历 std 字符串的段错误

c++ - 用特征值初始化 vector C++ 矩阵

c++ - 不正确的插值,opengl索引的vbo,顶点结构和glsl

javascript - Safari 的 RTCDataChannel 实现完全损坏了吗?

java - 如何使带有西里尔字符的字符串正确显示?

c++ - 使用 boost 数字绑定(bind)和 lapack 调用 gesvd 时出错

macos - 为什么我的 NSClipView 子类绘制时带有黑色背景,除非我指定 isOpaque NO? NSClipView 本身不这样做

c++ - 尝试在 cmake 项目中包含 boost 后出现链接错误

c++ - Boost进程间共享内存删除、权限和输出文件