Search code examples
cmakeconanmlpack

conan new template project build fails with header file not found


Following their template, I have:

conan new cmake_lib -d name=mlpackmsvc -d requires=mlpack/4.4.0

followed by conan build .

This ends up with error:

C:\test\src\mlpackmsvc.cpp(3,10): error C1083: Cannot open include file: 'mlpack.h': No such file or directory [C:\test\build\mlpackmsvc.vcxproj]
ERROR: conanfile.py (mlpackmsvc/0.1): Error in build() method, line 48
        cmake.build()
        ConanException: Error 1 while executing

My default profile is

[settings]
arch=x86_64
build_type=Release
compiler=msvc
compiler.cppstd=17
compiler.runtime=dynamic
compiler.version=194
os=Windows

How can this error be fixed?


Solution

  • The conan new templates doesn't generate the correct #include or function calls for any arbitrary dependency. I t just takes the -d requires=pkg/version argument and generates a placeholder #include "pkg.h" and a function call pkg();.

    This works if the other package called pkg was also generated with another conan new cmake_lib -d name=pkg command , but it won't work for any random third party library.

    So you need to change the placeholders header name and function call to something that really exists in mlpack.