-1
  • os: Mac
  • ide: CLion
  • library: uwebsockets

I'm trying to connect the library to my project, I use Conan, the package is downloaded, but the magic ends there, it gives errors in the python file, but I have no idea what to do with it, the python has been updated to version 3.10.8

conanfile.py

from conans import ConanFile, CMake


class HelloConan(ConanFile):
    name = "lib_example"
    version = "1.0"
    settings = "os", "compiler", "arch"
    generators = "cmake", "cmake_find_package"
        requires = [("uwebsockets/20.14.0")]

CMakeLists.txt

cmake_minimum_required(VERSION 3.23)
project(lib_example)

set(CMAKE_CXX_STANDARD 14)

add_executable(lib_example main.cpp)

find_package(uwebsockets REQUIRED)

if(uwebsockets FOUND)
    target_include_directories(${PROJECT_NAME} PRIVATE ${uwebsockets_INCLUDE_DIR})
    target_link_libraries(${PROJECT_NAME} PRIVATE ${uwebsockets_LIBRARIES})
endif()

terminal

❯ conan install ..
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=apple-clang
compiler.libcxx=libc++
compiler.version=12.0
os=Macos
os_build=Macos
[options]
[build_requires]
[env]

ERROR: Error loading conanfile at '/Users/lewz/Desktop/projects/coding/lib_example/conanfile.py': Unable to load conanfile in /Users/lewz/Desktop/projects/coding/lib_example/conanfile.py
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.0/Frameworks/Python.framework/Versions/3.11/lib/python3.11/imp.py", line 172, in load_source
    module = _load(spec)
             ^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 721, in _load
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 936, in exec_module
  File "<frozen importlib._bootstrap_external>", line 1074, in get_code
  File "<frozen importlib._bootstrap_external>", line 1004, in source_to_code
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/lewz/Desktop/projects/coding/lib_example/conanfile.py", line 9
    requires = [("uwebsockets/20.14.0")]
IndentationError: unexpected indent


~/Desktop/projects/coding/lib_example/cmake-build-debug master*

I don't know what to do next

genpfault
  • 51,148
  • 11
  • 85
  • 139

1 Answers1

1

The error you're getting isn't a conan error. It's a python error. You shouldn't have an indent on line 9.

Try this instead:

from conans import ConanFile, CMake


class HelloConan(ConanFile):
    name = "lib_example"
    version = "1.0"
    settings = "os", "compiler", "arch"
    generators = "cmake", "cmake_find_package"
    requires = ["uwebsockets/20.14.0"]
Caleb Kiage
  • 1,422
  • 12
  • 17
  • thanks! now i have another problem I seem to find all the paths and cmake says that there are no errors but the library is still not found `cmake_minimum_required(VERSION 3.23) project(example_lib) set(CMAKE_CXX_STANDARD 14) set(CMAKE_MODULE_PATH "${CMAKE_BINARY_DIR}; ${CMAKE_MODULE_PATH}") set(PROJECT_NAME "example_lib") add_executable(${PROJECT_NAME} main.cpp) find_package(uWebSockets) target_include_directories(${PROJECT_NAME} PRIVATE ${CONAN_INCLUDE_DIRS_uWebSockets}) target_link_libraries(${PROJECT_NAME} PRIVATE ${uWebSockets})` – Anton Lewz Nov 11 '22 at 20:53
  • What error do you get? Conan have a tutorial on using it with cmake projects. See here https://docs.conan.io/en/latest/getting_started.html – Caleb Kiage Nov 11 '22 at 21:38
  • 1
    @AntonLewz, it is better not to do a follow up, that would be a different issue than the one you posted. Also, there is some missing information, like the full actual commands used to install and build. My recommendation would be to start with something that works, like ``conan new hello/0.1 -m=cmake_lib``, do ``conan install`` + ``cmake ... -DCMAKE_TOOLCHAIN_FILE=...conan_toolchain.cmake``. Then add the ``requires = " and repeat, then add the ``find_package()`` and repeat, finally add the #include and some usage of the dependency. – drodri Nov 11 '22 at 21:38