(CMake)如何设置Boost的搜索路径?

时间:2017-10-13 04:05:34

标签: c++ boost cmake

我收到错误消息,说它无法找到提升。

我在Windows上使用bash。

CMakeError.log

Determining if the pthread_create exist failed with the following output:
Change Dir: /mnt/d/Downloads/gtborg-gtsam/gtborg-gtsam/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_434ae/fast"
/usr/bin/make -f CMakeFiles/cmTC_434ae.dir/build.make CMakeFiles/cmTC_434ae.dir/build
make[1]: Entering directory '/mnt/d/Downloads/gtborg-gtsam/gtborg-gtsam/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_434ae.dir/CheckSymbolExists.c.o
/usr/bin/cc    -std=c11   -Wall    -o CMakeFiles/cmTC_434ae.dir/CheckSymbolExists.c.o   -c /mnt/d/Downloads/gtborg-gtsam/gtborg-gtsam/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTC_434ae
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_434ae.dir/link.txt --verbose=1
/usr/bin/cc   -std=c11   -Wall     CMakeFiles/cmTC_434ae.dir/CheckSymbolExists.c.o  -o cmTC_434ae -rdynamic 
CMakeFiles/cmTC_434ae.dir/CheckSymbolExists.c.o: In function `main':
CheckSymbolExists.c:(.text+0x16): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_434ae.dir/build.make:97: recipe for target 'cmTC_434ae' failed
make[1]: *** [cmTC_434ae] Error 1
make[1]: Leaving directory '/mnt/d/Downloads/gtborg-gtsam/gtborg-gtsam/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_434ae/fast' failed
make: *** [cmTC_434ae/fast] Error 2

File /mnt/d/Downloads/gtborg-gtsam/gtborg-gtsam/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include <pthread.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef pthread_create
  return ((int*)(&pthread_create))[argc];
#else
  (void)argc;
  return 0;
#endif
}

Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /mnt/d/Downloads/gtborg-gtsam/gtborg-gtsam/build/CMakeFiles/CMakeTmp

Run Build Command:"/usr/bin/make" "cmTC_6aaf2/fast"
/usr/bin/make -f CMakeFiles/cmTC_6aaf2.dir/build.make CMakeFiles/cmTC_6aaf2.dir/build
make[1]: Entering directory '/mnt/d/Downloads/gtborg-gtsam/gtborg-gtsam/build/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_6aaf2.dir/CheckFunctionExists.c.o
/usr/bin/cc    -std=c11   -Wall -DCHECK_FUNCTION_EXISTS=pthread_create   -o CMakeFiles/cmTC_6aaf2.dir/CheckFunctionExists.c.o   -c /usr/share/cmake-3.5/Modules/CheckFunctionExists.c
Linking C executable cmTC_6aaf2
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_6aaf2.dir/link.txt --verbose=1
/usr/bin/cc   -std=c11   -Wall -DCHECK_FUNCTION_EXISTS=pthread_create    CMakeFiles/cmTC_6aaf2.dir/CheckFunctionExists.c.o  -o cmTC_6aaf2 -rdynamic -lpthreads 
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
CMakeFiles/cmTC_6aaf2.dir/build.make:97: recipe for target 'cmTC_6aaf2' failed
make[1]: *** [cmTC_6aaf2] Error 1
make[1]: Leaving directory '/mnt/d/Downloads/gtborg-gtsam/gtborg-gtsam/build/CMakeFiles/CMakeTmp'
Makefile:126: recipe for target 'cmTC_6aaf2/fast' failed
make: *** [cmTC_6aaf2/fast] Error 2

所以我试着像这样设置Boost搜索路径:

CMakeList.txt

SET(Boost_NO_SYSTEM_PATHS 1)

SET(BOOST_ROOT&#34; / usr / lib / x86_64-linux-gnu /&#34;)

SET(BOOST_INCLUDEDIR&#34; / usr / include / boost&#34;)

SET(BOOST_LIBRARYDIR&#34; / usr / lib / x86_64-linux-gnu /&#34;)

CMakeList.txt 中的完整Boost部分是:

# Find boost
    SET (Boost_NO_SYSTEM_PATHS 1)
    SET (BOOST_ROOT "/usr/lib/x86_64-linux-gnu/")
    SET (BOOST_INCLUDEDIR "/usr/include/boost")
    SET (BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu/")

# To change the path for boost, you will need to set:
# BOOST_ROOT: path to install prefix for boost
# Boost_NO_SYSTEM_PATHS: set to true to keep the find script from ignoring BOOST_ROOT
# If using Boost shared libs, disable auto linking
if(MSVC)
    # Some libraries, at least Boost Program Options, rely on this to export DLL symbols
    # Disable autolinking
    if(NOT Boost_USE_STATIC_LIBS)
        add_definitions(-DBOOST_ALL_NO_LIB)
      add_definitions(-DBOOST_ALL_DYN_LINK)
    endif()
endif()

find_package(Boost 1.43 COMPONENTS serialization system filesystem thread program_options date_time timer chrono)
option(gtest_disable_pthreads "Disable uses of pthreads in gtest." OFF)

# Required components
if(NOT Boost_SERIALIZATION_LIBRARY OR NOT Boost_SYSTEM_LIBRARY OR NOT Boost_FILESYSTEM_LIBRARY OR
    NOT Boost_THREAD_LIBRARY OR NOT Boost_DATE_TIME_LIBRARY)
  message(FATAL_ERROR "Missing required Boost components >= v1.43, please install/upgrade Boost or configure your search paths.")
endif()

option(GTSAM_DISABLE_NEW_TIMERS "Disables using Boost.chrono for timing" OFF)
# Allow for not using the timer libraries on boost < 1.48 (GTSAM timing code falls back to old timer library)
set(GTSAM_BOOST_LIBRARIES
    ${Boost_SERIALIZATION_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY}
    ${Boost_THREAD_LIBRARY} ${Boost_DATE_TIME_LIBRARY})
if (GTSAM_DISABLE_NEW_TIMERS)
    message("WARNING:  GTSAM timing instrumentation manually disabled")
    add_definitions(-DGTSAM_DISABLE_NEW_TIMERS)
else()
    if(Boost_TIMER_LIBRARY)
      list(APPEND GTSAM_BOOST_LIBRARIES ${Boost_TIMER_LIBRARY} ${Boost_CHRONO_LIBRARY})
    else()
      list(APPEND GTSAM_BOOST_LIBRARIES rt) # When using the header-only boost timer library, need -lrt
      message("WARNING:  GTSAM timing instrumentation will use the older, less accurate, Boost timer library because boost older than 1.48 was found.")
    endif()
endif()


if(NOT (${Boost_VERSION} LESS 105600))
    message("Ignoring Boost restriction on optional lvalue assignment from rvalues")
    add_definitions(-DBOOST_OPTIONAL_ALLOW_BINDING_TO_RVALUES -DBOOST_OPTIONAL_CONFIG_ALLOW_BINDING_TO_RVALUES)
endif()

但它仍然抱怨它无法找到Boost。

任何人都可以一步一步地帮助我吗?

0 个答案:

没有答案