0

I'm working with a C++ project using Conan for dependency management and CMake as the build system.

I created a new Conan package for a static library called mylib. The header files are located under the path:

mylib/include/mylib/MyHeader_Interface.h

relevant conan_pkg.py content looks like this:

from conans import CMake, ConanFile

@property
    def conan(self):
        return self._conan

def get_exports_sources(self) -> Iterable[str]:
    return (
        "src/**",
        "include/**",
        "cmake/*",
        "CMakeLists.txt",
        "version",
        "LICENSE",
        "tests/**"
    )

def package_info(self):
     super().package_info()
     self.conan.cpp_info.includedirs = [
     self.conan.cpp_info.rootpath + '/include/mylib']

Conan version 1.64.0

After creating the package, I confirmed the header is located at:

~/.conan/data/mylib/0.0.1/user/channel/package/<package-id>/include/mylib/mylib/MyHeader_Interface.h

In the consuming core project, I use:

find_package(mylib REQUIRED)
target_link_libraries(${target_name} PUBLIC mylib::mylib)

However, when compiling, I get the following error:

fatal error: mylib/MyHeader_Interface.h: No such file or directory

Question: Why is the header not found during compilation, even though the package seems to have it in the expected include path? Do I need to adjust the include directory layout or change how I reference the headers in the consuming project?

5
  • 1
    You are not specifying the Conan version. It seems it is Conan 1.X which was replaced by Conan2 more than 2 years ago, and Conan 1 is no longer recommended. I'd suggest specifying clearly the Conan version. Then, there are a lot of details missing, for example the generators in the consumer side are very important, using CMakeDeps is the recommended one even in Conan 1. I'd suggest to submit a ticket with a full minimal reproduction example to github.com/conan-io/conan/issues Commented Jun 22 at 21:16
  • Note there are a lot of details missing, for example `` self.conan.cpp_info`` is not something built-in in Conan (it should be self.cpp_info), so it might belong to some python-requires that this recipe is using, so it would be necessary to provide also the python-requires. Same for get_exports_sources(), that method doesn't belong to Conan. Commented Jun 22 at 21:19
  • conan in conan_pkg.py refers to an instance of the ConanFile class. from conans import CMake, ConanFile Commented Jun 22 at 22:09
  • Have you tried to examine the compilation command line which gives you the error message? That way you could check whether the include directory is correctly passed. BTW, the documentation for Conan tells about relative paths in the includedirs field, but you use the absolute one. Commented Jun 22 at 22:14
  • 1
    I found the issue — the find_package(mylib ...) was missing in the CMake configuration of the consuming project's tests. Commented Jun 23 at 9:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.