Travis-CI - Linux - 安装后缺少libdl.so

时间:2018-01-04 00:06:08

标签: c++ linux cmake travis-ci

操作: 使用travis-ci通过 linux x64 下的 gcc 编译器构建C ++ / C代码。使用 libdl 函数需要通过-ldl链接。

预期行为 libdl beind成功地联系在一起。

实际行为 libdl链接失败(命令行中缺少DSO)。 使用 clang 时会成功链接。两个作业都通过< ldconfig -p |打印grep libdl':

libdl.so.2 (libc6,x86-64, OS ABI: Linux 2.6.24) => /lib/x86_64-linux-gnu/libdl.so.2
libdl.so (libc6,x86-64, OS ABI: Linux 2.6.24) => /usr/lib/x86_64-linux-gnu/libdl.so

在CMakeLists.txt中的用法:

...
add_executable(SOE 
    ${SOE_INC} ${SOE_SRC}
)

set_target_properties(SOE PROPERTIES
    ENABLE_EXPORTS 1
    VERSION ${SOE_VERSION}
)

target_link_libraries (SOE bgfx bimg bcommon 
-lGL -lXext -lX11 -lpthread -L./ -ldl
)
...

Travis-CI日志:

...
libc6-dev is already the newest version (2.19-0ubuntu6.13).
libc6-dev set to manually installed.
...
$ export CXX=g++
$ export CC=gcc
$ gcc --version
gcc (Ubuntu 4.8.5-2ubuntu1~14.04.1) 4.8.5
...
//job clang
The command "if [[ "$TRAVIS_OS_NAME" == "linux" && "$CXX" == "clang++-4.0" ]]; then (rm -fr ~/.cmake && ldconfig -p | grep libdl && pwd && mkdir -p $BUILD_ROOT && cd $BUILD_ROOT && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/tmp/usr -DCMAKE_LIBRARY_PATH=/tmp/usr/lib                          $SOE_BUILD_OPTIONS $SOURCE_ROOT && make && cd UnitTests && ./UnitTests ); fi" 
exited with 0.

//job gcc
Scanning dependencies of target SOE
[ 93%] Building CXX object SOE/CMakeFiles/SOE.dir/src/SOE.cpp.o
[ 94%] Linking CXX executable SOE
/usr/bin/ld: ../bx/libbx.a(os.cpp.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/libdl.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [SOE/SOE-1.0] Error 1
make[1]: *** [SOE/CMakeFiles/SOE.dir/all] Error 2
make: *** [all] Error 2
The command "if [[ "$TRAVIS_OS_NAME" == "linux" && "$CXX" == "g++-6"       ]]; then (rm -fr ~/.cmake && ldconfig -p | grep libdl && pwd && mkdir -p $BUILD_ROOT && cd $BUILD_ROOT && cmake -DCMAKE_BUILD_TYPE=Debug   -DCMAKE_PREFIX_PATH=/tmp/usr -DCMAKE_LIBRARY_PATH=/tmp/usr/lib -DSOE_ENABLE_COVERAGE=ON $SOE_BUILD_OPTIONS $SOURCE_ROOT && make && cd UnitTests && ./UnitTests ); fi" 
exited with 2.
...

.travis.yml

# This file configures the build and run environment on https://travis-ci.org/

# Specify the operating systems on which to test for.
os:
  - linux

# For details on building a C++ project see: https://docs.travis-ci.com/user/languages/cpp/
language: cpp

dist: trusty

# Specifiy which compiler or compilers to test against.
# For details, see https://docs.travis-ci.com/user/languages/cpp/#Choosing-compilers-to-test-against
compiler:
  - clang
  - gcc

# Specify explicitly which branches to build or not build
# For details see: https://docs.travis-ci.com/user/customizing-the-build/#Building-Specific-Branches
branches:
  only:
    - master

# Specify which OS X image to use.
# "xcode8" is supposed to provide a macosx10.11 SK preinstalled.
# For details see: https://docs.travis-ci.com/user/osx-ci-environment/
osx_image: xcode8

sudo: false

# https://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.tar.gz

# Specify which "apt" packages to install/update.
# For white-listed aliases, see https://github.com/travis-ci/apt-source-whitelist/blob/master/ubuntu.json
#
addons:
  apt:
    sources:
      - deadsnakes
      - ubuntu-toolchain-r-test
      - george-edison55-precise-backports
      - llvm-toolchain-trusty-4.0
    packages:
      - build-essential
      - cmake
      - cmake-data
      - clang-4.0
      - g++-6
      - gcc-6
      - libc6-dev
      - xorg-dev
      - libx11-dev
      - libxmu-dev
      - libxi-dev
      - libgl1-mesa-dev
      - libosmesa-dev
      - x11proto-core-dev
      - lcov
      - ggcov

before_install:
  - gem install coveralls-lcov

# Install stage. Setup dependencies that can't be setup as addon packages.
#
# Additional notes:
# Linux seems to usually support "sha256sum". OS X meanwhile calls it "shasum".
# For dumping compiler macros: $CXX -dM -E - < /dev/null | sort
# Don't use backslashes for line folding/breaking; they don't work for that.
#
install:
  - |
    if [ "$CXX" = "g++" ]
    then
      export CXX="g++-6" CC="gcc-6"
      wget http://downloads.sourceforge.net/ltp/lcov-1.13.tar.gz
      tar xf lcov-1.13.tar.gz
      mkdir -p /tmp/usr
      make -C lcov-1.13/ PREFIX=/tmp/usr install
    fi
  - if [ "$CXX" = "clang++" ]; then export CXX="clang++-4.0" CC="clang-4.0"; fi
  - |
    echo CXX=$CXX HOME=$HOME TRAVIS_BUILD_DIR=$TRAVIS_BUILD_DIR
    cmake --version
    export SOURCE_ROOT="${TRAVIS_BUILD_DIR}" BUILD_ROOT="${TRAVIS_BUILD_DIR}-Build"
    SOE_BUILD_OPTIONS="-DSOE_BUILD_UNIT_TESTS=ON"
  - |
    if [ "$CXX" = "clang++" ]; then
      SOE_BUILD_OPTIONS="$SOE_BUILD_OPTIONS -DSOE_BUILD_BENCHMARK=ON"
    fi
    echo $SOE_BUILD_OPTIONS

script:
  - if [[ "$TRAVIS_OS_NAME" == "linux" && "$CXX" == "clang++-4.0" ]]; then (rm -fr ~/.cmake && ldconfig -p | grep libdl && pwd && mkdir -p $BUILD_ROOT && cd $BUILD_ROOT && cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/tmp/usr -DCMAKE_LIBRARY_PATH=/tmp/usr/lib                          $SOE_BUILD_OPTIONS $SOURCE_ROOT && make && cd UnitTests && ./UnitTests ); fi
  - if [[ "$TRAVIS_OS_NAME" == "linux" && "$CXX" == "g++-6"       ]]; then (rm -fr ~/.cmake && ldconfig -p | grep libdl && pwd && mkdir -p $BUILD_ROOT && cd $BUILD_ROOT && cmake -DCMAKE_BUILD_TYPE=Debug   -DCMAKE_PREFIX_PATH=/tmp/usr -DCMAKE_LIBRARY_PATH=/tmp/usr/lib -DSOE_ENABLE_COVERAGE=ON $SOE_BUILD_OPTIONS $SOURCE_ROOT && make && cd UnitTests && ./UnitTests ); fi
...

0 个答案:

没有答案