c++ - 使用 cmake 和 travis boost 1.67 静态库

标签 c++ boost cmake travis-ci

大家好。 我尝试在 travis-ci 中使用 cmake 和 boost 1.67 构建我的 c++ 项目。 以下是源文件。

在我的 linux 计算机上安装了来自源代码的 cmake 3.13.4 和来自源代码的 boost-1.67,所有库(静态和动态)都在目录“/usr/local/lib/”中并且一切正常.但是在 travis-ci 中,我每次都会看到这条消息:

Unable to find the requested Boost libraries.
  Boost version: 1.67.0
  Boost include path: /usr/include
  Could not find the following static Boost libraries:
          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.

yml文件:

language: cpp
dist: xenial
sudo: false
os: linux


matrix:
  include:
    - env: COMPILER=g++-8 BUILD=Debug STANDARD=14
      compiler: gcc
      addons:
        apt:
          update: true
          sources:
            - sourceline: 'ppa:mhier/libboost-latest'
            - ubuntu-toolchain-r-test
          packages:
            - g++-8
            - boost1.67
    - env: COMPILER=g++-8 BUILD=Release STANDARD=14
      compiler: gcc
      addons:
        apt:
          update: true
          sources:
            - sourceline: 'ppa:mhier/libboost-latest'
            - ubuntu-toolchain-r-test
          packages:
            - g++-8
            - boost1.67

before_script:
  - wget https://cmake.org/files/v3.13/cmake-3.13.4-Linux-x86_64.sh
  - sudo sh cmake-3.13.4-Linux-x86_64.sh -- --skip-license --prefix=/usr

script:
  - cmake .
  - cmake --build .
  - cmake --build . --target package

制作:

cmake_minimum_required(VERSION 3.10)  
project(hcch VERSION 0.1.${VERSION_BUILD})

set(BOOST_ROOT /usr/include/boost/)

# For my linux
#set(BOOST_LIBRARYDIR /usr/local/lib)

# For travis-ci host
set(BOOST_LIBRARYDIR /usr/lib/x86_64-linux-gnu)

set(Boost_USE_STATIC_LIBS ON)
include_directories (${Boost_INCLUDE_DIRS})
link_directories (${Boost_LIBRARY_DIRS})

find_package(Boost 1.67 COMPONENTS program_options REQUIRED)
find_package(LLVM REQUIRED CONFIG)

configure_file (
        "${PROJECT_SOURCE_DIR}/version.h.in"
        "${PROJECT_BINARY_DIR}/version.h"
)

set(CMAKE_CXX_STANDARD 14)

add_executable(hcch hcch.cpp SourcesCreator.cpp SourcesCreator.h)

set_target_properties(hcch PROPERTIES
        CXX_STANDARD 14
        CXX_STANDARD_REQUIRED ON
        COMPILE_OPTIONS -Wpedantic -Wall -Wextra
        )

TARGET_LINK_LIBRARIES( hcch ${BOOST_LIBRARYDIR}/libboost_program_options.a )

也许静态库不是从 ppa:mhier/libboost-latest 安装的? 如果有人遇到,请告诉我如何解决。

这是我的项目 https://github.com/angelskieglazki/hcch 问候,最大

最佳答案

我可以确认从 ppa:mhier/libboost-latest 构建的 libboost 当前不构建静态库,仅共享。

如果您必须使用比 libboost-all-dev 提供的版本更高的 Boost 版本,那么您将需要从源代码编译 boost,尽管您会冒超时的风险。相关说明可在 Boost's best practice handbook 中找到.

关于c++ - 使用 cmake 和 travis boost 1.67 静态库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55314745/

相关文章:

c++ - 如果输入是安全的,是否有可能利用易受攻击的函数?

C++ 异构列表

c++ - C++ 中的一行用户输入赋值

c++ - 代码块 osx 快板

cmake - 安装问题: Cmake error : include could not find load file: yarpl-exports. cmake

cmake - 查找定义目标的目录

c++ - 如何获取 Boost Graph Library 中属性的类型

c++ - boost::program_options 和位置参数的问题

c++ - boost::lexical_cast<int> ("-138.8468953457983248") 抛出异常

cmake - 将文件依赖项添加到自定义目标