简体   繁体   中英

How to fix unknown command error in CMake, when I using Conan?

I've got CMakeLists.txt file:

project(ip_filter LANGUAGES CXX)
cmake_minimum_required(VERSION 2.8)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(ip_filter ip_filter.cpp)
target_link_libraries(ip_filter ${CONAN_LIBS})

At the same folder, I've got a conanfile.txt:

[requires]
range-v3/0.9.1@ericniebler/stable

[generators]
cmake

When I tried to build it, using:

$ cmake CMakeLists.txt

I've got this output:

CMake Error at CMakeLists.txt:4 (include):
  include could not find load file:

    /home/bogdasar/Documents/C++_Programming/ip_filter/conanbuildinfo.cmake


CMake Error at CMakeLists.txt:5 (conan_basic_setup):
  Unknown CMake command "conan_basic_setup".


-- Configuring incomplete, errors occurred!
See also "/home/bogdasar/Documents/C++_Programming/ip_filter/CMakeFiles/CMakeOutput.log".

I was stuck on the same issue for a while. After going through few threads I found the solution. Here I am summarizing the same.

Problem here is cmake is unable to find conanbuildinfo.cmake. This file should be generated when you call conan install.

If it is not getting generated then you should include cmake generator in conanfile.py. Like below:

generators = "virtualenv", "virtualrunenv", "cmake_find_package", "cmake"

or you can mention the same in your conan profile. Like below:

[generators]
cmake

Once this file is generated, cmake should be able to find it. And conan_basic_setup() step should pass.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM