Search code examples
cmakeconan

Include path error in conan cmake configuration


conanfile.txt //i am using local repo

[requires]
libxml2/2.9.0@conan/stable

[generators]
cmake

CMakeLists.txt

 cmake_minimum_required(VERSION 3.4)
 project(testlibxml)

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

 add_executable(test_xml_lib test_xml.cpp)

test_xml.cpp

 #include <libxml/xlink.h>

 int main(){

     return 0;
 }

I expect includes to be resolved properly, but i am getting below error

error: libxml/xlink.h: No such file or directory. 

It works if i add below line in CmakeLists.txt

include_directories(${CONAN_INCLUDE_DIRS}/libxml2)

Solution

  • I don't know where are you getting that version of the libxml2 package, because it is not in conan-center:

    $ conan search libxml* -r=conan-center
    Existing package recipes:
    
    libxml2/2.9.3@bincrafters/stable
    libxml2/2.9.8@bincrafters/stable
    

    So what you are using might be an old, stale, or broken version from somewhere else. Changing your conanfile.txt:

    [requires]
    libxml2/2.9.8@bincrafters/stable
    
    [generators]
    cmake
    

    And I have checked it works (at least in Windows)