admin管理员组

文章数量:1356914

I have problem with using libraries for C++ using Conan2 and Cmake in Linux. Files are:

CMakeList.txt in root:

cmake_minimum_required(VERSION 3.5)

set(CMAKE_CXX_COMPILER "/usr/bin/clang++")                
# set(CMAKE_CXX_COMPILER "/usr/bin/g++-14")

project(exercises
        VERSION 1.0
        LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_COMPILE_WARNING_AS_ERROR)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_BUILD_TYPE Debug) # TODO change type to Release for build commitment

option (FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)."
 TRUE)
if (${FORCE_COLORED_OUTPUT})
    if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
       add_compile_options (-fdiagnostics-color=always)
    elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
       add_compile_options (-fcolor-diagnostics)
    endif ()
endif ()

enable_testing()

include_directories(includes)
add_subdirectory(src)
add_subdirectory(tests)


target_compile_options(main PRIVATE -fopenmp -g -ggdb -Werror -Wall -pedantic
# -Wno-parentheses
 -Wnull-dereference -Wextra -Wshadow -Wnon-virtual-dtor
#  -ftime-report) # to get detailed compilation timer
 -finput-charset=UTF-8 )# enable UTF-8 support for GCC

CMakeList.txt in a src dir:

find_package(LibtorrentRasterbar REQUIRED)
include_directories(${LibtorrentRasterbar_INCLUDE_DIRS})

add_executable(main main_new.cpp )
    
target_link_libraries(main PRIVATE
    LibtorrentRasterbar::torrent-rasterbar)

main.cpp

#include <iostream>
#include <libtorrent/session.hpp>
#include <libtorrent/torrent_info.hpp>
#include <libtorrent/alert_types.hpp>
#include <libtorrent/torrent_status.hpp>

using namespace libtorrent;

int main() {
    session s;

    std::string torrent_file = "../../test_folder-d984f67af9917b214cd8b6048ab5624c7df6a07a.torrent";

    try {
        torrent_info info(torrent_file);

        add_torrent_params p;
        p.ti = std::make_shared<torrent_info>(info);
        p.save_path = "./";

        torrent_handle h = s.add_torrent(p);

        std::cout << "Started..." << std::endl;

        while (!h.status().is_seeding) {
            s.post_torrent_updates();
            std::vector<alert*> alerts;
            s.pop_alerts(&alerts);

            for (alert* a : alerts) {
                if (auto* ta = alert_cast<torrent_finished_alert>(a)) {
                    std::cout << "Fully downloaded " << ta->torrent_name() << std::endl;
                }
                else if (alert_cast<torrent_error_alert>(a)) {
                    std::cerr << "Ошибка: " << a->message() << std::endl;
                }
            }

            torrent_status status = h.status();
            std::cout << "Progress: " << status.progress * 100 << "%\r" << std::flush;

            std::this_thread::sleep_for(std::chrono::milliseconds(1000));
        }

        std::cout << "\nComplete << std::endl;
    }
    catch (std::exception& e) {
        std::cerr << "Error " << e.what() << std::endl;
        return 1;
    }

    return 0;
} 

conanfile.txt

[requires]
gtest/1.15.0
ncurses/6.5
libcurl/8.10.1
libtorrent/2.0.1


[generators]
CMakeDeps
CMakeToolchain

[layout]
cmake_layout

And the problem is that some libs are found just fine, but others give error messages like that:

CMake Error at src/CMakeLists.txt:1 (find_package):
  By not providing "FindLibtorrentRasterbar.cmake" in CMAKE_MODULE_PATH this
  project has asked CMake to find a package configuration file provided by
  "LibtorrentRasterbar", but CMake did not find one.

  Could not find a package configuration file provided by
  "LibtorrentRasterbar" with any of the following names:

    LibtorrentRasterbarConfig.cmake
    libtorrentrasterbar-config.cmake

  Add the installation prefix of "LibtorrentRasterbar" to CMAKE_PREFIX_PATH
  or set "LibtorrentRasterbar_DIR" to a directory containing one of the above
  files.  If "LibtorrentRasterbar" provides a separate development package or
  SDK, be sure it has been installed.

Is it config files errors or what?

No solutions are currently found. There is some solutions for specific libs, but no overall solution.

本文标签: linuxCould not find *Configcmake in several C cmake projectsStack Overflow