Point FindBoost CMAKE to boost_python Windows 10,

2019-04-17 11:09发布

问题:

My high level goal is to install the BGSlibrary which requires boost for python on Windows 10 using Visual Studio 2017. I compiled opencv and boost (1.64.0) from source using cmake 3.9.0. During cmake for BGSLIBRARY I get

$ cmake -DBGS_PYTHON_SUPPORT=ON -DBOOST_ROOT="C:/Program Files/boost_1_64_0/" ..
-- BGSLIBRARY WITH PYTHON SUPPORT: ON
-- OpenCV library status:
--     version: 3.3.0
CMake Error at C:/Program Files (x86)/CMake/share/cmake-3.9/           Modules/FindBoost.cmake:1877 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.64.0

  Boost include path: C:/Program Files/boost_1_64_0

  Could not find the following Boost libraries:

          boost_python

  No Boost libraries were found.  You may need to 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:75 (find_package)

I've seen lots of questions on the cmake findboost module. Okay lets start from here.

  1. I downloaded and extract boost 1.64.0 and placed it here

  1. I ran bootstrap.bat and .b2 to generate the build boost

    C:\Program Files\boost_1_64_0>b2 toolset=msvc-14.1 --with-python --user-config=user-config.jam

with a user config

import toolset : using ;
using msvc : 14.1 ;
using python 
  : 2.7  # Version
  : C:\\Python27\\python.exe  # Interpreter
  : C:\\Python27\\include  # inc dir
  : C:\\Python27\\libs  # link libs
  : # conditions
  ;

I can see python source here

and can confirm that from within the Visual Studio 2017 command prompt I build boost with python support and it finds all targets successfully.

I can see a bunch of "python" .lib files here. Reading other questions suggests that is where it goes.

But I can't seem to get cmake to see it. I've tried changing the name libboost_python to boost_python. I've tried pointing in cmake -DBOOST_ROOT, or -DBOOST_LIBRARYDIR (or non-debg, -BOOST_LIBRARYDIR). I've tried adding to the lib dir to PATH. But nothing seems to work. Is this a cmake problem, a incomplete boost installation or a problem with BGSLibrary?

EDIT

To answer @utopia, the CMakeList section in question reads

if(BGS_PYTHON_SUPPORT)
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)

find_package(Boost REQUIRED COMPONENTS python)
find_package(PythonLibs REQUIRED)

message(STATUS "Boost library status:")
message(STATUS "    version: ${Boost_VERSION}")
message(STATUS "    libraries: ${Boost_LIBRARIES}")
message(STATUS "    include path: ${Boost_INCLUDE_DIRS}")

message(STATUS "Python library status:")
message(STATUS "    version: ${PYTHON_VERSION}")
message(STATUS "    libraries: ${PYTHON_LIBRARIES}")
message(STATUS "    include path: ${PYTHON_INCLUDE_DIRS}")

endif()

Does this mean that the .lib should be literally named python.lib? With no other characters or perhaps boost_python.lib. Is it that specific?

  1. Building Boost.Python

回答1:

@utopia led me to the right solution. The .lib needs to be literally named boost_python.lib, not appended with the visual studio compiler version, boost version etc. I was able to successfully build after that, no cmake flags needed.