C++ Travis CI报告Vulkan项目gcc-7的链接器错误

C++ Travis CI报告Vulkan项目gcc-7的链接器错误,c++,cmake,conan,C++,Cmake,Conan,我的CMake+conan设置有问题,导致Travis CI中的链接器错误: 有很多未定义的引用,这意味着链接器无法以某种方式找到库文件。它找不到spdlog,因此链接器错误不是Vulkan特定的 我的conanfile.py设置如下所示: from conans import ConanFile, CMake class InexorConan(ConanFile): settings = ( "os", "compiler", "

我的CMake+conan设置有问题,导致Travis CI中的链接器错误:

有很多未定义的引用,这意味着链接器无法以某种方式找到库文件。它找不到spdlog,因此链接器错误不是Vulkan特定的

我的
conanfile.py
设置如下所示:

from conans import ConanFile, CMake

class InexorConan(ConanFile):

    settings = (
        "os",
        "compiler",
        "build_type",
        "arch"
    )

    requires = (
        "benchmark/1.5.0",
        "glm/0.9.9.7",
        "gtest/1.10.0",
        "spdlog/1.5.0",
        "glfw/3.3.2@bincrafters/stable",
        "toml11/3.1.0",
        "imgui/1.75",
        "stb/20200203",
        "nlohmann_json/3.7.3",
    )

    generators = "cmake"

    def imports(self):
        # Copies all dll files from packages bin folder to my "bin" folder (win)
        self.copy("*.dll", dst="bin", src="bin")
        # Copies all dylib files from packages lib folder to my "lib" folder (macosx)
        self.copy("*.dylib*", dst="lib", src="lib") # From lib to lib
        # Copies all so files from packages lib folder to my "lib" folder (linux)
        self.copy("*.so*", dst="lib", src="lib") # From lib to lib

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

cmake_minimum_required(VERSION 3.4)

project(inexor-vulkan-renderer)

file(
    GLOB_RECURSE source_files
    "src/*.hpp"
    "src/*.cpp"
    "tests/*.*"
    "benchmarks/*.*"
)

# Use the folder structure in source code directory as project structure in Visual Studio.
function(assign_source_group)
    foreach (source_files IN ITEMS ${ARGN})
        if (IS_ABSOLUTE "${source_files}")
            file(RELATIVE_PATH _source_rel "${CMAKE_CURRENT_SOURCE_DIR}" "${source_files}")
        else ()
            set(_source_rel "${source_files}")
        endif ()
        get_filename_component(_source_path "${_source_rel}" PATH)
        string(REPLACE "/" "\\" _source_path_msvc "${_source_path}")
        source_group("${_source_path_msvc}" FILES "${source_files}")
    endforeach ()
endfunction(assign_source_group)

set(NORMAL_SOURCE_FILES)
set(TEST_SOURCE_FILES)
set(BENCHMARK_SOURCE_FILES)

# Sort source files by tests and benchmarks.
foreach (file ${source_files})
    if (file MATCHES ".*_test.*")
        set(TEST_SOURCE_FILES ${TEST_SOURCE_FILES} ${file})
    elseif (file MATCHES ".*_benchmark.*")
        set(BENCHMARK_SOURCE_FILES ${BENCHMARK_SOURCE_FILES} ${file})
    else ()
        set(NORMAL_SOURCE_FILES ${NORMAL_SOURCE_FILES} ${file})
    endif ()
endforeach ()

if (NOT CMAKE_VERSION VERSION_LESS 3.7.0)
    message(STATUS "Using module to find Vulkan")
    find_package(Vulkan)
endif ()

# Dependency setup via conan.
# Download conan executer in case it does not exists.
if (NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/conan.cmake")
    message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
    file(
        DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.14/conan.cmake"
        "${CMAKE_CURRENT_BINARY_DIR}/conan.cmake"
    )
endif ()

include(${CMAKE_CURRENT_BINARY_DIR}/conan.cmake)

conan_check(VERSION 1.19.1 REQUIRED)

conan_cmake_run(
    CONANFILE conanfile.py
    BASIC_SETUP
    BUILD outdated
    PROFILE default
    PROFILE_AUTO build_type
    KEEP_RPATHS
)

# Use the folder structure in source code directory as project structure in Visual Studio.
assign_source_group(${NORMAL_SOURCE_FILES})
assign_source_group(${TEST_SOURCE_FILES})
assign_source_group(${BENCHMARK_SOURCE_FILES})

add_executable(inexor-vulkan-renderer src/main.cpp ${NORMAL_SOURCE_FILES})
conan_target_link_libraries(inexor-vulkan-renderer)
target_compile_features(inexor-vulkan-renderer PRIVATE cxx_std_17)

target_include_directories(inexor-vulkan-renderer PRIVATE Vulkan::Vulkan)
target_link_libraries(inexor-vulkan-renderer Vulkan::Vulkan fmt spdlog)

# Use multiple threads to generate code.
if (MSVC)
    target_compile_options(inexor-vulkan-renderer PRIVATE "/MP")
endif ()

# Use root folder of the repository as working directory in Visual Studio debugger!
# Otherwise Visual Studio can't find any files like shaders or textures.
if (WIN32)
    set_property(TARGET inexor-vulkan-renderer PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
endif ()

file(
    GLOB_RECURSE NORMAL_SOURCE_FILES_WITHOUT_MAIN
    "src/vulkan-renderer/*"
)

add_executable(inexor-vulkan-renderer-tests ${NORMAL_SOURCE_FILES_WITHOUT_MAIN} ${TEST_SOURCE_FILES})
conan_target_link_libraries(inexor-vulkan-renderer-tests)
target_compile_features(inexor-vulkan-renderer-tests PRIVATE cxx_std_17)

target_include_directories(inexor-vulkan-renderer-tests PRIVATE Vulkan::Vulkan)
target_link_libraries(inexor-vulkan-renderer-tests Vulkan::Vulkan spdlog)

# Use root folder of the repository as working directory in Visual Studio debugger!
# Otherwise Visual Studio can't find any files like shaders or textures.
if (WIN32)
    set_property(TARGET inexor-vulkan-renderer PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
endif ()

if (MSVC)
    # Use multiple threads to compile the code.
    target_compile_options(inexor-vulkan-renderer-tests PRIVATE "/MP")
endif ()

add_executable(inexor-vulkan-renderer-benchmarks ${NORMAL_SOURCE_FILES_WITHOUT_MAIN} ${BENCHMARK_SOURCE_FILES})
conan_target_link_libraries(inexor-vulkan-renderer-benchmarks Vulkan::Vulkan spdlog)
target_compile_features(inexor-vulkan-renderer-benchmarks PRIVATE cxx_std_17)
target_include_directories(inexor-vulkan-renderer-benchmarks PRIVATE Vulkan::Vulkan)

target_include_directories(inexor-vulkan-renderer-benchmarks PRIVATE Vulkan::Vulkan)
target_link_libraries(inexor-vulkan-renderer-benchmarks spdlog gtest)

if (WIN32)
    set_property(TARGET inexor-vulkan-renderer-benchmarks PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
endif ()

# Use multiple threads to compile the code.
if (MSVC)
    target_compile_options(inexor-vulkan-renderer-benchmarks PRIVATE "/MP")
endif ()

我的
CMakeLists.txt
如下所示:

from conans import ConanFile, CMake

class InexorConan(ConanFile):

    settings = (
        "os",
        "compiler",
        "build_type",
        "arch"
    )

    requires = (
        "benchmark/1.5.0",
        "glm/0.9.9.7",
        "gtest/1.10.0",
        "spdlog/1.5.0",
        "glfw/3.3.2@bincrafters/stable",
        "toml11/3.1.0",
        "imgui/1.75",
        "stb/20200203",
        "nlohmann_json/3.7.3",
    )

    generators = "cmake"

    def imports(self):
        # Copies all dll files from packages bin folder to my "bin" folder (win)
        self.copy("*.dll", dst="bin", src="bin")
        # Copies all dylib files from packages lib folder to my "lib" folder (macosx)
        self.copy("*.dylib*", dst="lib", src="lib") # From lib to lib
        # Copies all so files from packages lib folder to my "lib" folder (linux)
        self.copy("*.so*", dst="lib", src="lib") # From lib to lib

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

cmake_minimum_required(VERSION 3.4)

project(inexor-vulkan-renderer)

file(
    GLOB_RECURSE source_files
    "src/*.hpp"
    "src/*.cpp"
    "tests/*.*"
    "benchmarks/*.*"
)

# Use the folder structure in source code directory as project structure in Visual Studio.
function(assign_source_group)
    foreach (source_files IN ITEMS ${ARGN})
        if (IS_ABSOLUTE "${source_files}")
            file(RELATIVE_PATH _source_rel "${CMAKE_CURRENT_SOURCE_DIR}" "${source_files}")
        else ()
            set(_source_rel "${source_files}")
        endif ()
        get_filename_component(_source_path "${_source_rel}" PATH)
        string(REPLACE "/" "\\" _source_path_msvc "${_source_path}")
        source_group("${_source_path_msvc}" FILES "${source_files}")
    endforeach ()
endfunction(assign_source_group)

set(NORMAL_SOURCE_FILES)
set(TEST_SOURCE_FILES)
set(BENCHMARK_SOURCE_FILES)

# Sort source files by tests and benchmarks.
foreach (file ${source_files})
    if (file MATCHES ".*_test.*")
        set(TEST_SOURCE_FILES ${TEST_SOURCE_FILES} ${file})
    elseif (file MATCHES ".*_benchmark.*")
        set(BENCHMARK_SOURCE_FILES ${BENCHMARK_SOURCE_FILES} ${file})
    else ()
        set(NORMAL_SOURCE_FILES ${NORMAL_SOURCE_FILES} ${file})
    endif ()
endforeach ()

if (NOT CMAKE_VERSION VERSION_LESS 3.7.0)
    message(STATUS "Using module to find Vulkan")
    find_package(Vulkan)
endif ()

# Dependency setup via conan.
# Download conan executer in case it does not exists.
if (NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/conan.cmake")
    message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
    file(
        DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.14/conan.cmake"
        "${CMAKE_CURRENT_BINARY_DIR}/conan.cmake"
    )
endif ()

include(${CMAKE_CURRENT_BINARY_DIR}/conan.cmake)

conan_check(VERSION 1.19.1 REQUIRED)

conan_cmake_run(
    CONANFILE conanfile.py
    BASIC_SETUP
    BUILD outdated
    PROFILE default
    PROFILE_AUTO build_type
    KEEP_RPATHS
)

# Use the folder structure in source code directory as project structure in Visual Studio.
assign_source_group(${NORMAL_SOURCE_FILES})
assign_source_group(${TEST_SOURCE_FILES})
assign_source_group(${BENCHMARK_SOURCE_FILES})

add_executable(inexor-vulkan-renderer src/main.cpp ${NORMAL_SOURCE_FILES})
conan_target_link_libraries(inexor-vulkan-renderer)
target_compile_features(inexor-vulkan-renderer PRIVATE cxx_std_17)

target_include_directories(inexor-vulkan-renderer PRIVATE Vulkan::Vulkan)
target_link_libraries(inexor-vulkan-renderer Vulkan::Vulkan fmt spdlog)

# Use multiple threads to generate code.
if (MSVC)
    target_compile_options(inexor-vulkan-renderer PRIVATE "/MP")
endif ()

# Use root folder of the repository as working directory in Visual Studio debugger!
# Otherwise Visual Studio can't find any files like shaders or textures.
if (WIN32)
    set_property(TARGET inexor-vulkan-renderer PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
endif ()

file(
    GLOB_RECURSE NORMAL_SOURCE_FILES_WITHOUT_MAIN
    "src/vulkan-renderer/*"
)

add_executable(inexor-vulkan-renderer-tests ${NORMAL_SOURCE_FILES_WITHOUT_MAIN} ${TEST_SOURCE_FILES})
conan_target_link_libraries(inexor-vulkan-renderer-tests)
target_compile_features(inexor-vulkan-renderer-tests PRIVATE cxx_std_17)

target_include_directories(inexor-vulkan-renderer-tests PRIVATE Vulkan::Vulkan)
target_link_libraries(inexor-vulkan-renderer-tests Vulkan::Vulkan spdlog)

# Use root folder of the repository as working directory in Visual Studio debugger!
# Otherwise Visual Studio can't find any files like shaders or textures.
if (WIN32)
    set_property(TARGET inexor-vulkan-renderer PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
endif ()

if (MSVC)
    # Use multiple threads to compile the code.
    target_compile_options(inexor-vulkan-renderer-tests PRIVATE "/MP")
endif ()

add_executable(inexor-vulkan-renderer-benchmarks ${NORMAL_SOURCE_FILES_WITHOUT_MAIN} ${BENCHMARK_SOURCE_FILES})
conan_target_link_libraries(inexor-vulkan-renderer-benchmarks Vulkan::Vulkan spdlog)
target_compile_features(inexor-vulkan-renderer-benchmarks PRIVATE cxx_std_17)
target_include_directories(inexor-vulkan-renderer-benchmarks PRIVATE Vulkan::Vulkan)

target_include_directories(inexor-vulkan-renderer-benchmarks PRIVATE Vulkan::Vulkan)
target_link_libraries(inexor-vulkan-renderer-benchmarks spdlog gtest)

if (WIN32)
    set_property(TARGET inexor-vulkan-renderer-benchmarks PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
endif ()

# Use multiple threads to compile the code.
if (MSVC)
    target_compile_options(inexor-vulkan-renderer-benchmarks PRIVATE "/MP")
endif ()

此设置适用于Visual Studio 2019。 也许柯南无法将库传递给目标

conan_target_link_libraries(inexor-vulkan-renderer-tests)
target_link_libraries(inexor-vulkan-renderer-tests Vulkan::Vulkan spdlog)
这是我的Travis设置:

os: linux
language: python
python: "3.7"
dist: xenial

os: linux
addons:
  apt:
    sources:
      - ubuntu-toolchain-r-test
    packages:
      - g++-7

before_script:
  - sudo apt-get install
  - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
  - sudo apt-get update -qq

install:
  - pip install conan
  - conan user
  - sudo apt-get install -qq g++-7
  - wget https://github.com/premake/premake-core/releases/download/v5.0.0-alpha11/premake-5.0.0-alpha11-linux.tar.gz?Human=true -O premake-5.0.0-alpha11-linux.tar.gz
  - tar -xzvf premake-5.0.0-alpha11-linux.tar.gz
  - sudo apt-get -qq update
  - sudo apt-get install -y libassimp-dev libglm-dev graphviz libxcb-dri3-0 libxcb-present0 libpciaccess0 cmake libpng-dev libxcb-dri3-dev libx11-dev libx11-xcb-dev libmirclient-dev libwayland-dev libxrandr-dev
  - export VK_VERSION=1.2.131.1
  - wget -O vulkansdk-linux-x86_64-$VK_VERSION.tar.gz https://sdk.lunarg.com/sdk/download/$VK_VERSION/linux/vulkansdk-linux-x86_64-$VK_VERSION.tar.gz
  - tar zxf vulkansdk-linux-x86_64-$VK_VERSION.tar.gz
  - export VULKAN_SDK=$TRAVIS_BUILD_DIR/$VK_VERSION/x86_64

script:
  - export CC=gcc-7
  - export CXX=g++-7
  - conan remote add bincrafters https://api.bintray.com/conan/bincrafters/public-conan
  - conan install .
  - cmake -DCMAKE_BUILD_TYPE=Release .
  - cmake --build . --target inexor-vulkan-renderer
  - ctest .

notifications:
  email:
    recipients:
      - info@inexor.org
    on_success: change
    on_failure: always

几天来我一直在努力解决这个问题。 如果有人能给我一个提示,我将不胜感激

诚挚的问候
Johannes.

注意,您的链接器正在查找属于libstdc++11的
std::\uuuuCXX11::basic\uString
。但是,您的柯南配置文件使用的是libstdc++,这是不兼容的,您可以在日志的开头看到它

您需要使用libstdc++11配置您的柯南配置文件:

conan profile update settings.compiler.libcxx=libstdc++11 default 
进一步阅读:

-步骤5


非常感谢!这就只剩下这个了:/home/travis/.conan/data/libx11/1.6.8/bincrafters/stable/package/ee7e8c22a4645bde16d8dacf89e8f5b242755c89/lib/libx11.so:未定义对`reallocarray@GLIBC_2.26类似的错误。你下载的软件包是在Ubuntu artful 17.10上构建的,它的glibc版本(2.26)比你当前的发行版xenial 16.04更新。您有两个选择:使用bionic 18.04更新您的travis,或者通过添加--build从源代码构建所有包,但这需要几个小时。我更喜欢第一个选择,所以你可以用GCC8代替。非常感谢!作为澄清,travis作业日志行622中实际上有一个警告:
警告:GCC旧ABI兼容性
,这会导致更改conan配置文件
设置.compiler.libcxx
的向后兼容性