C ++ - cmake找不到boost库

时间:2016-03-14 19:47:55

标签: c++ boost cmake

对于一个项目,我必须结合使用cmake和boost来生成C ++构建(avro)。我安装了以下程序:

  • cmake v3.4.3
  • boost v1.55.0

但是当在.bat文件中执行带有以下语句的命令时(此批处理文件由第3方提供者提供),

set BOOST_ROOT=D:\software\boost_1_55_0\
set BOOST_INCLUDEDIR=D:\software\boost_1_55_0\boost
set BOOST_LIBRARYDIR=D:\software\boost_1_55_0\lib32-msvc-12.0

set PATH=%MSVS_HOME%\VC;%BOOST_LIBRARYDIR%;%BOOST_ROOT%;%BOOST_INCLUDEDIR%;%PATH%

call vcvarsall.bat

cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug

(备注:MSVS_HOME是Visual Studio安装到的目录,其他路径由我自己设置。) cmake引发错误,如下所示

CMake Error at D:/software/cmake_3.4.3/share/cmake-3.4/Modules/FindBoost.cmake:1247 (message):
 Unable to find the requested Boost libraries.

 Boost version: 1.55.0

 Boost include path: D:/software/boost_1_55_0

 Could not find the following Boost libraries:

          boost_filesystem
          boost_system
          boost_program_options

 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:54 (find_package)

-- Configuring incomplete, errors occurred!
See also "D:/kaa/kaaBuild/avro-src-1.7.5/lang/c++/build.win/CMakeFiles/CMakeOutput.log".

但令我感到惊讶的是因为在boost目录中,您可以找到所需的库。下面是我用来查找所需Boost库的PS命令。

PS D:\software\boost_1_55_0\lib32-msvc-12.0> Get-ChildItem boost_file* -name
boost_filesystem-vc120-1_55.dll
boost_filesystem-vc120-1_55.lib
boost_filesystem-vc120-gd-1_55.dll
boost_filesystem-vc120-gd-1_55.lib
boost_filesystem-vc120-mt-1_55.dll
boost_filesystem-vc120-mt-1_55.lib
boost_filesystem-vc120-mt-gd-1_55.dll
boost_filesystem-vc120-mt-gd-1_55.lib

PS D:\software\boost_1_55_0\lib32-msvc-12.0> Get-ChildItem boost_system* -name
boost_system-vc120-1_55.dll
boost_system-vc120-1_55.lib
boost_system-vc120-gd-1_55.dll
boost_system-vc120-gd-1_55.lib
boost_system-vc120-mt-1_55.dll
boost_system-vc120-mt-1_55.lib
boost_system-vc120-mt-gd-1_55.dll
boost_system-vc120-mt-gd-1_55.lib

PS D:\software\boost_1_55_0\lib32-msvc-12.0> Get-ChildItem boost_program_opt* -name
boost_program_options-vc120-1_55.dll
boost_program_options-vc120-1_55.lib
boost_program_options-vc120-gd-1_55.dll
boost_program_options-vc120-gd-1_55.lib
boost_program_options-vc120-mt-1_55.dll
boost_program_options-vc120-mt-1_55.lib
boost_program_options-vc120-mt-gd-1_55.dll

如您所见,所需文件位于正确的位置。

问题: 我对cmake不熟悉。可能问题出在cmake列表(如下所示)还是其他地方的问题?我已经研究过以下问题:

  • c++ - cmake cannot find boost libraries 答案是配置问题。但由于我几乎没有使用过cmake,我不确定配置是否正确。我没有配置它。这些文件是由第三方提供商提供给我的......

  • C++ - CMAKE cannot find boost 没有答案,但在评论中,它提到了变量。我在这里设置正确(我认为......)

  • Cmake doesn't find Boost 答案告诉我在FIND_PACKAGE(Boost)之前添加这两行,但我的cmakelists.txt(此处如下)不包含它。

  • C++ - CMake is not able to find boost libraries 答案很模糊,我不知道哪一个会有用。有一个答案提到了可以添加到cmakelists.txt的代码段。我不确定我是否应该这样做。 (如上所述,文件由第三方提供商提供)

我还在StackOverflow之外检查了以下答案:

  • this,它讲述环境变量,我已经拥有的东西
  • this,它提到了libdev boost的一个版本。我认为我有最新版本。 (见上文,我有Boost 1.55)
  • this,提及删除cmake文件。但是,它适用于orocos,我不使用的东西。我认为这也不会解决我的问题。但是无论如何我都试过了,不,没有帮助。

那么,我该怎么做才能解决这个问题?我是否忽略了某些事情?错过了重要的事情?

下面有两个片段,即上面执行失败后生成的cmake列表和cmake日志。我希望这些有用。

的CMakeLists.txt:

#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#
cmake_minimum_required (VERSION 2.6)

set (CMAKE_LEGACY_CYGWIN_WIN32 0)

if (NOT DEFINED CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS)
    set (CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
endif()

if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/VERSION.txt)
    file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION.txt" AVRO_VERSION)
else (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/VERSION.txt)
    file(READ "${CMAKE_CURRENT_SOURCE_DIR}/../../share/VERSION.txt"
        AVRO_VERSION)
endif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/VERSION.txt)

set (AVRO_VERSION_MAJOR ${AVRO_VERSION})
set (AVRO_VERSION_MINOR "0")

project (Avro-cpp)

if (WIN32 AND NOT CYGWIN AND NOT MSYS)
add_definitions (/EHa)
add_definitions (
    -DBOOST_REGEX_DYN_LINK
    -DBOOST_FILESYSTEM_DYN_LINK
    -DBOOST_SYSTEM_DYN_LINK
    -DBOOST_PROGRAM_OPTIONS_DYN_LINK
    -DBOOST_ALL_NO_LIB)
endif()

if (CMAKE_COMPILER_IS_GNUCXX)
    set(CMAKE_CXX_FLAGS "-Wall")
endif ()


find_package (Boost 1.38 REQUIRED
    COMPONENTS filesystem system program_options)

add_definitions (${Boost_LIB_DIAGNOSTIC_DEFINITIONS})

include_directories (api ${CMAKE_CURRENT_BINARY_DIR} ${Boost_INCLUDE_DIRS})

set (AVRO_SOURCE_FILES
        impl/Compiler.cc impl/Node.cc
        impl/NodeImpl.cc impl/ResolverSchema.cc impl/Schema.cc
        impl/Types.cc impl/ValidSchema.cc impl/Zigzag.cc
        impl/BinaryEncoder.cc impl/BinaryDecoder.cc
        impl/Stream.cc impl/FileStream.cc
        impl/Generic.cc
        impl/DataFile.cc
        impl/parsing/Symbol.cc
        impl/parsing/ValidatingCodec.cc
        impl/parsing/JsonCodec.cc
        impl/parsing/ResolvingDecoder.cc
        impl/json/JsonIO.cc
        impl/json/JsonDom.cc
        impl/Resolver.cc impl/Validator.cc
        )

add_library (avrocpp SHARED ${AVRO_SOURCE_FILES})

set_property (TARGET avrocpp
    APPEND PROPERTY COMPILE_DEFINITIONS AVRO_DYN_LINK)

add_library (avrocpp_s STATIC ${AVRO_SOURCE_FILES})

set_property (TARGET avrocpp avrocpp_s
    APPEND PROPERTY COMPILE_DEFINITIONS AVRO_SOURCE)

set_target_properties (avrocpp PROPERTIES
    VERSION ${AVRO_VERSION_MAJOR}.${AVRO_VERSION_MINOR})

set_target_properties (avrocpp_s PROPERTIES
    VERSION ${AVRO_VERSION_MAJOR}.${AVRO_VERSION_MINOR})

target_link_libraries (avrocpp ${Boost_LIBRARIES})

add_executable (precompile test/precompile.cc)

target_link_libraries (precompile avrocpp_s ${Boost_LIBRARIES})

macro (gencpp file ns)
    add_custom_command (OUTPUT ${ns}.hh
        COMMAND precompile ${CMAKE_CURRENT_SOURCE_DIR}/jsonschemas/${file}
            ${file}
        COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/scripts/gen-cppcode.py
            -n ${ns} -i ${file} -o ${ns}.hh
        DEPENDS precompile ${CMAKE_CURRENT_SOURCE_DIR}/jsonschemas/${file})
    add_custom_target(${ns} DEPENDS ${ns}.hh)
endmacro (gencpp)

if (CYGWIN OR NOT WIN32)
    gencpp (bigrecord testgen)
    gencpp (bigrecord2 testgen2)
endif ()

macro (gen file ns)
    add_custom_command (OUTPUT ${file}.hh
        COMMAND avrogencpp
            -p -
            -i ${CMAKE_CURRENT_SOURCE_DIR}/jsonschemas/${file}
            -o ${file}.hh -n ${ns} -U
        DEPENDS avrogencpp ${CMAKE_CURRENT_SOURCE_DIR}/jsonschemas/${file})
    add_custom_target (${file}_hh DEPENDS ${file}.hh)
endmacro (gen)

gen (bigrecord testgen)
gen (bigrecord2 testgen2)
gen (tweet testgen3)
gen (union_array_union uau)
gen (union_map_union umu)
gen (union_conflict uc)
gen (recursive rec)
gen (reuse ru)
gen (circulardep cd)

add_executable (avrogencpp impl/avrogencpp.cc)
target_link_libraries (avrogencpp avrocpp_s ${Boost_LIBRARIES})

enable_testing()

macro (unittest name)
    add_executable (${name} test/${name}.cc)
    target_link_libraries (${name} avrocpp ${Boost_LIBRARIES})
    add_test (NAME ${name} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
        COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${name})
endmacro (unittest)

unittest (buffertest)
unittest (unittest)
unittest (SchemaTests)
unittest (CodecTests)
unittest (StreamTests)
unittest (SpecificTests)
unittest (DataFileTests)
unittest (JsonTests)
unittest (AvrogencppTests)

if (CYGWIN OR NOT WIN32)
    unittest (testgentest)
    add_dependencies (testgentest testgen testgen2)
endif()

add_dependencies (AvrogencppTests bigrecord_hh bigrecord2_hh tweet_hh
    union_array_union_hh union_map_union_hh union_conflict_hh
    recursive_hh reuse_hh circulardep_hh)

include (InstallRequiredSystemLibraries)

set (CPACK_PACKAGE_FILE_NAME "avrocpp-${AVRO_VERSION_MAJOR}")

include (CPack)

install (TARGETS avrocpp avrocpp_s
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
    RUNTIME DESTINATION lib)

install (TARGETS avrogencpp RUNTIME DESTINATION bin)

install (DIRECTORY api/ DESTINATION include/avro
    FILES_MATCHING PATTERN *.hh)

if (NOT CMAKE_BUILD_TYPE)
    set (CMAKE_BUILD_TYPE Release CACHE STRING
      "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
      FORCE)
endif (NOT CMAKE_BUILD_TYPE)

和cmake日志:

The system is: Windows - 10.0.10586 - AMD64
Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: C:/Program Files (x86)/Visual Studio 14.0/VC/bin/cl.exe 
Build flags: 
Id flags: 

The output was:
0
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

CMakeCCompilerId.c
Microsoft (R) Incremental Linker Version 14.00.23506.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:CMakeCCompilerId.exe 
CMakeCCompilerId.obj 


Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "CMakeCCompilerId.exe"

Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "CMakeCCompilerId.obj"

The C compiler identification is MSVC, found in "D:/kaa/kaaBuild/avro-src-1.7.5/lang/c++/build.win/CMakeFiles/3.4.3/CompilerIdC/CMakeCCompilerId.exe"

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: C:/Program Files (x86)/Visual Studio 14.0/VC/bin/cl.exe 
Build flags: 
Id flags: 

The output was:
0
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23506 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

CMakeCXXCompilerId.cpp
Microsoft (R) Incremental Linker Version 14.00.23506.0
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:CMakeCXXCompilerId.exe 
CMakeCXXCompilerId.obj 


Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "CMakeCXXCompilerId.exe"

Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "CMakeCXXCompilerId.obj"

The CXX compiler identification is MSVC, found in "D:/kaa/kaaBuild/avro-src-1.7.5/lang/c++/build.win/CMakeFiles/3.4.3/CompilerIdCXX/CMakeCXXCompilerId.exe"

Determining if the C compiler works passed with the following output:
Change Dir: D:/kaa/kaaBuild/avro-src-1.7.5/lang/c++/build.win/CMakeFiles/CMakeTmp

Run Build Command:"nmake" "/NOLOGO" "cmTC_279c3\fast"
    "C:\Program Files (x86)\Visual Studio 14.0\VC\BIN\nmake.exe" -f CMakeFiles\cmTC_279c3.dir\build.make /nologo -L                  CMakeFiles\cmTC_279c3.dir\build

Building C object CMakeFiles/cmTC_279c3.dir/testCCompiler.c.obj

    C:\PROGRA~2\VISUAL~1.0\VC\bin\cl.exe  @C:\Users\geire\AppData\Local\Temp\nm8C78.tmp

testCCompiler.c

Linking C executable cmTC_279c3.exe

    D:\software\cmake_3.4.3\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_279c3.dir --manifests  -- C:\PROGRA~2\VISUAL~1.0\VC\bin\link.exe /nologo @CMakeFiles\cmTC_279c3.dir\objects1.rsp @C:\Users\geire\AppData\Local\Temp\nm8DF0.tmp



Detecting C compiler ABI info compiled with the following output:
Change Dir: D:/kaa/kaaBuild/avro-src-1.7.5/lang/c++/build.win/CMakeFiles/CMakeTmp

Run Build Command:"nmake" "/NOLOGO" "cmTC_f6e85\fast"
    "C:\Program Files (x86)\Visual Studio 14.0\VC\BIN\nmake.exe" -f CMakeFiles\cmTC_f6e85.dir\build.make /nologo -L                  CMakeFiles\cmTC_f6e85.dir\build

Building C object CMakeFiles/cmTC_f6e85.dir/CMakeCCompilerABI.c.obj

    C:\PROGRA~2\VISUAL~1.0\VC\bin\cl.exe  @C:\Users\geire\AppData\Local\Temp\nm908F.tmp

CMakeCCompilerABI.c

Linking C executable cmTC_f6e85.exe

    D:\software\cmake_3.4.3\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_f6e85.dir --manifests  -- C:\PROGRA~2\VISUAL~1.0\VC\bin\link.exe /nologo @CMakeFiles\cmTC_f6e85.dir\objects1.rsp @C:\Users\geire\AppData\Local\Temp\nm90CF.tmp



Determining if the CXX compiler works passed with the following output:
Change Dir: D:/kaa/kaaBuild/avro-src-1.7.5/lang/c++/build.win/CMakeFiles/CMakeTmp

Run Build Command:"nmake" "/NOLOGO" "cmTC_38c4b\fast"
    "C:\Program Files (x86)\Visual Studio 14.0\VC\BIN\nmake.exe" -f CMakeFiles\cmTC_38c4b.dir\build.make /nologo -L                  CMakeFiles\cmTC_38c4b.dir\build

Building CXX object CMakeFiles/cmTC_38c4b.dir/testCXXCompiler.cxx.obj

    C:\PROGRA~2\VISUAL~1.0\VC\bin\cl.exe  @C:\Users\geire\AppData\Local\Temp\nm92E1.tmp

testCXXCompiler.cxx

Linking CXX executable cmTC_38c4b.exe

    D:\software\cmake_3.4.3\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_38c4b.dir --manifests  -- C:\PROGRA~2\VISUAL~1.0\VC\bin\link.exe /nologo @CMakeFiles\cmTC_38c4b.dir\objects1.rsp @C:\Users\geire\AppData\Local\Temp\nm9330.tmp



Detecting CXX compiler ABI info compiled with the following output:
Change Dir: D:/kaa/kaaBuild/avro-src-1.7.5/lang/c++/build.win/CMakeFiles/CMakeTmp

Run Build Command:"nmake" "/NOLOGO" "cmTC_c9164\fast"
    "C:\Program Files (x86)\Visual Studio 14.0\VC\BIN\nmake.exe" -f CMakeFiles\cmTC_c9164.dir\build.make /nologo -L                  CMakeFiles\cmTC_c9164.dir\build

Building CXX object CMakeFiles/cmTC_c9164.dir/CMakeCXXCompilerABI.cpp.obj

    C:\PROGRA~2\VISUAL~1.0\VC\bin\cl.exe  @C:\Users\geire\AppData\Local\Temp\nm95DE.tmp

CMakeCXXCompilerABI.cpp

Linking CXX executable cmTC_c9164.exe

    D:\software\cmake_3.4.3\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_c9164.dir --manifests  -- C:\PROGRA~2\VISUAL~1.0\VC\bin\link.exe /nologo @CMakeFiles\cmTC_c9164.dir\objects1.rsp @C:\Users\geire\AppData\Local\Temp\nm962E.tmp





Detecting CXX [] compiler features compiled with the following output:
Change Dir: D:/kaa/kaaBuild/avro-src-1.7.5/lang/c++/build.win/CMakeFiles/CMakeTmp

Run Build Command:"nmake" "/NOLOGO" "cmTC_2af8b\fast"
    "C:\Program Files (x86)\Visual Studio 14.0\VC\BIN\nmake.exe" -f CMakeFiles\cmTC_2af8b.dir\build.make /nologo -L                  CMakeFiles\cmTC_2af8b.dir\build

Building CXX object CMakeFiles/cmTC_2af8b.dir/feature_tests.cxx.obj

    C:\PROGRA~2\VISUAL~1.0\VC\bin\cl.exe  @C:\Users\geire\AppData\Local\Temp\nm98CC.tmp

feature_tests.cxx

Linking CXX executable cmTC_2af8b.exe

    D:\software\cmake_3.4.3\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_2af8b.dir --manifests  -- C:\PROGRA~2\VISUAL~1.0\VC\bin\link.exe /nologo @CMakeFiles\cmTC_2af8b.dir\objects1.rsp @C:\Users\geire\AppData\Local\Temp\nm992B.tmp



    Feature record: CXX_FEATURE:1cxx_alias_templates
    Feature record: CXX_FEATURE:1cxx_alignas
    Feature record: CXX_FEATURE:1cxx_alignof
    Feature record: CXX_FEATURE:1cxx_attributes
    Feature record: CXX_FEATURE:1cxx_attribute_deprecated
    Feature record: CXX_FEATURE:1cxx_auto_type
    Feature record: CXX_FEATURE:1cxx_binary_literals
    Feature record: CXX_FEATURE:1cxx_constexpr
    Feature record: CXX_FEATURE:1cxx_contextual_conversions
    Feature record: CXX_FEATURE:1cxx_decltype
    Feature record: CXX_FEATURE:1cxx_decltype_auto
    Feature record: CXX_FEATURE:1cxx_default_function_template_args
    Feature record: CXX_FEATURE:1cxx_defaulted_functions
    Feature record: CXX_FEATURE:1cxx_defaulted_move_initializers
    Feature record: CXX_FEATURE:1cxx_delegating_constructors
    Feature record: CXX_FEATURE:1cxx_deleted_functions
    Feature record: CXX_FEATURE:1cxx_digit_separators
    Feature record: CXX_FEATURE:1cxx_enum_forward_declarations
    Feature record: CXX_FEATURE:1cxx_explicit_conversions
    Feature record: CXX_FEATURE:1cxx_extended_friend_declarations
    Feature record: CXX_FEATURE:1cxx_extern_templates
    Feature record: CXX_FEATURE:1cxx_final
    Feature record: CXX_FEATURE:1cxx_func_identifier
    Feature record: CXX_FEATURE:1cxx_generalized_initializers
    Feature record: CXX_FEATURE:1cxx_generic_lambdas
    Feature record: CXX_FEATURE:1cxx_inheriting_constructors
    Feature record: CXX_FEATURE:1cxx_inline_namespaces
    Feature record: CXX_FEATURE:1cxx_lambdas
    Feature record: CXX_FEATURE:1cxx_lambda_init_captures
    Feature record: CXX_FEATURE:1cxx_local_type_template_args
    Feature record: CXX_FEATURE:1cxx_long_long_type
    Feature record: CXX_FEATURE:1cxx_noexcept
    Feature record: CXX_FEATURE:1cxx_nonstatic_member_init
    Feature record: CXX_FEATURE:1cxx_nullptr
    Feature record: CXX_FEATURE:1cxx_override
    Feature record: CXX_FEATURE:1cxx_range_for
    Feature record: CXX_FEATURE:1cxx_raw_string_literals
    Feature record: CXX_FEATURE:1cxx_reference_qualified_functions
    Feature record: CXX_FEATURE:1cxx_return_type_deduction
    Feature record: CXX_FEATURE:1cxx_right_angle_brackets
    Feature record: CXX_FEATURE:1cxx_rvalue_references
    Feature record: CXX_FEATURE:1cxx_sizeof_member
    Feature record: CXX_FEATURE:1cxx_static_assert
    Feature record: CXX_FEATURE:1cxx_strong_enums
    Feature record: CXX_FEATURE:1cxx_template_template_parameters
    Feature record: CXX_FEATURE:1cxx_thread_local
    Feature record: CXX_FEATURE:1cxx_trailing_return_types
    Feature record: CXX_FEATURE:1cxx_unicode_literals
    Feature record: CXX_FEATURE:1cxx_uniform_initialization
    Feature record: CXX_FEATURE:1cxx_unrestricted_unions
    Feature record: CXX_FEATURE:1cxx_user_literals
    Feature record: CXX_FEATURE:1cxx_variadic_macros
    Feature record: CXX_FEATURE:1cxx_variadic_templates

0 个答案:

没有答案