CMake:“find_package(Boost)”效果很好,但另一个没有

时间:2015-06-13 00:56:04

标签: c++ boost cmake

我正在为跨平台构建Boost Asio的timer example。所以我使用CMake自动化构建系统。

文件结构:

- timer
  - build (Just empty)
  - dep
    - boost
      - boost
      - doc
      - libs
      - ...
      - CMakeLists.txt (Important)
      - ...
    - CMakeLists.txt
  - src
    - CMakeLists.txt
    - timer.cpp
  - CMakeLists.txt

dep/boost/CMakeLists.txt之外的其他CMake脚本只是在子目录中包含一些脚本或配置项目,就是这样!

DEP /升压/的CMakeLists.txt:

# Boost settings
set(BOOST_ROOT ${CMAKE_CURRENT_LIST_DIR})
set(Boost_USE_STATIC_LIBS     ON)
set(Boost_USE_MULTITHREADED   ON)
set(Boost_USE_STATIC_RUNTIME  ON)

# Specify Boost libraries that will use.
set(boost_components system date_time regex)
set(boost_components_option --with-system --with-date_time --with-regex)

# Find compiled Boost
find_package(Boost COMPONENTS ${boost_components}) <-- STMT1
# If couldn't find it, compile Boost before process.
if(NOT ${Boost_FOUND})
  if(WIN32)
    set(bootstrap_name bootstrap.bat)
    set(bootstrap_command bootstrap.bat)
    set(b2_name b2.exe)
    set(b2_command b2.exe)
    set(b2_variant debug,release)
  else()
    set(bootstrap_name bootstrap.sh)
    set(bootstrap_command ./bootstrap.sh)
    set(b2_name b2)
    set(b2_command ./b2)
    set(b2_variant release)
  endif()
  if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/${bootstrap_name})
    if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/${b2_name})
      if(UNIX)
        execute_process(COMMAND chmod +x
        ${bootstrap_name} tools/build/src/engine/build.sh
        WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
      endif()
      execute_process(COMMAND ${bootstrap_command}
                      WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
    endif()
  else()
    message(FATAL_ERROR "Could NOT find ${bootstrap_name}")
  endif()
  if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/${b2_name})
    execute_process(COMMAND ${b2_command} ${boost_components_option}
                    variant=${b2_variant} link=static threading=multi
                    runtime-link=static
                    WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
  else()
    message(FATAL_ERROR "Could NOT find ${b2_name}")
  endif()
  # After compile Boost, re-find it.
  find_package(Boost REQUIRED COMPONENTS ${boost_components}) <-- STMT2
endif()

好的......当我在控制台上的cmake ..目录中命令build时,它在Windows 10上运行得很好,但在Ubuntu 14.04上出现问题。问题是CMake无法在编译之后找到Boost库(Boost库,在STMT2)。那不是全部。奇怪的是,如果在cmake ..目录中只有build命令(在STMT1中完全相同),CMake会毫无问题地找到它。可以理解的是,在发生问题之前,所有必需的Boost库都在dep/boost/stage/lib目录中编译。显然,STMT1STMT2完全相同,只是指定了REQUIRED。我检查了一些与Boost相关的变量,并用适当的值重新声明它,但它无法帮助我。

第一个命令控制台输出:

user@user-pc:~/desktop/timer/build$ cmake ..
-- The C compiler identification is GNU 4.8.2
-- The CXX compiler identification is GNU 4.8.2
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Could NOT find Boost
Building Boost.Build engine with toolset gcc... tools/build/src/engine/bin.linuxx86_64/b2
Detecting Python version... 2.7
Detecting Python root... /usr
Unicode/ICU support for Boost.Regex?... not found.
Generating Boost.Build configuration in project-config.jam...

Bootstrapping is done. To build, run:

    ./b2

To adjust configuration, edit 'project-config.jam'.
Further information:

   - Command line help:
     ./b2 --help

   - Getting started guide: 
     http://www.boost.org/more/getting_started/unix-variants.html

   - Boost.Build documentation:
     http://www.boost.org/build/doc/html/index.html

Performing configuration checks

    - 32-bit                   : no
    - 64-bit                   : yes
    - arm                      : no
    - mips1                    : no
    - power                    : no
    - sparc                    : no
    - x86                      : yes

Building the Boost C++ Libraries.


    - has_icu builds           : no

Component configuration:

    - atomic                   : not building
    - chrono                   : not building
    - container                : not building
    - context                  : not building
    - coroutine                : not building
    - date_time                : building
    - exception                : not building
    - filesystem               : not building
    - graph                    : not building
    - graph_parallel           : not building
    - iostreams                : not building
    - locale                   : not building
    - log                      : not building
    - math                     : not building
    - mpi                      : not building
    - program_options          : not building
    - python                   : not building
    - random                   : not building
    - regex                    : building
    - serialization            : not building
    - signals                  : not building
    - system                   : building
    - test                     : not building
    - thread                   : not building
    - timer                    : not building
    - wave                     : not building

...patience...
...found 1092 targets...
...updating 51 targets...
common.mkdir stage
common.mkdir stage/lib
common.mkdir bin.v2/libs/date_time
common.mkdir bin.v2/libs/date_time/build
common.mkdir bin.v2/libs/date_time/build/gcc-4.8
common.mkdir bin.v2/libs/date_time/build/gcc-4.8/release
common.mkdir bin.v2/libs/date_time/build/gcc-4.8/release/link-static
common.mkdir bin.v2/libs/date_time/build/gcc-4.8/release/link-static/runtime-link-static
common.mkdir bin.v2/libs/date_time/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi
common.mkdir bin.v2/libs/date_time/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/gregorian
gcc.compile.c++ bin.v2/libs/date_time/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/gregorian/greg_month.o
gcc.compile.c++ bin.v2/libs/date_time/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/gregorian/greg_weekday.o
gcc.compile.c++ bin.v2/libs/date_time/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/gregorian/date_generators.o
gcc.archive bin.v2/libs/date_time/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/libboost_date_time.a
common.copy stage/lib/libboost_date_time.a
common.mkdir bin.v2/libs/regex/build/gcc-4.8/release
common.mkdir bin.v2/libs/regex/build/gcc-4.8/release/link-static
common.mkdir bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static
common.mkdir bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/c_regex_traits.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/cpp_regex_traits.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/cregex.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/fileiter.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/icu.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/instances.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/posix_api.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/regex.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/regex_debug.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/regex_raw_buffer.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/regex_traits_defaults.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/static_mutex.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/w32_regex_traits.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/wc_regex_traits.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/wide_posix_api.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/winstances.o
gcc.compile.c++ bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/usinstances.o
gcc.archive bin.v2/libs/regex/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/libboost_regex.a
common.copy stage/lib/libboost_regex.a
common.mkdir bin.v2/libs/system
common.mkdir bin.v2/libs/system/build
common.mkdir bin.v2/libs/system/build/gcc-4.8
common.mkdir bin.v2/libs/system/build/gcc-4.8/release
common.mkdir bin.v2/libs/system/build/gcc-4.8/release/link-static
common.mkdir bin.v2/libs/system/build/gcc-4.8/release/link-static/runtime-link-static
common.mkdir bin.v2/libs/system/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi
gcc.compile.c++ bin.v2/libs/system/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/error_code.o
gcc.archive bin.v2/libs/system/build/gcc-4.8/release/link-static/runtime-link-static/threading-multi/libboost_system.a
common.copy stage/lib/libboost_system.a
...updated 51 targets...


The Boost C++ Libraries were successfully built!

The following directory should be added to compiler include paths:

    /home/user/desktop/timer/dep/boost

The following directory should be added to linker library paths:

    /home/user/desktop/timer/dep/boost/stage/lib

CMake Error at /usr/share/cmake-2.8/Modules/FindBoost.cmake:1131 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.58.0

  Boost include path: /home/user/desktop/timer/dep/boost

  Could not find the following static Boost libraries:

          boost_system
          boost_date_time
          boost_regex

  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):
  dep/boost/CMakeLists.txt:50 (find_package)
  dep/CMakeLists.txt:2 (include)
  CMakeLists.txt:6 (include)


-- Configuring incomplete, errors occurred!
See also "/home/user/desktop/timer/build/CMakeFiles/CMakeOutput.log".

第二个命令控制台输出:

user@user-pc:~/desktop/timer/build$ cmake ..
-- Boost version: 1.58.0
-- Found the following Boost libraries:
--   system
--   date_time
--   regex
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/desktop/timer/build

到底发生了什么?以及如何解决?感谢。

0 个答案:

没有答案
相关问题