question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Header-only Library how to include

See original GitHub issue

I want to use a header only github project, so I created my conanfile.py with this in it:

from conans import ConanFile, tools


class SimpleSignalConan(ConanFile):
    name = "SimpleSignal"
    version = "master"

    def source(self):
        git = tools.Git(folder=self.name)
        git.clone('https://github.com/larspensjo/SimpleSignal.git', branch=self.version)

In my CMakeLists.txt, I did the following:

if(CONAN_EXPORTED) # in conan local cache
    # standard conan installation, deps will be defined in conanfile.py
    # and not necessary to call conan again, conan is already running
    include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
    conan_basic_setup()
else() # in user space
    include(${CMAKE_BINARY_DIR}/conan.cmake)
    # Make sure to use conanfile.py to define dependencies, to stay consistent
    conan_cmake_run(CONANFILE conanfile.py
                    BASIC_SETUP)
endif()

In my main.cpp, I tried doing #include <SimpleSignal.h>, but it didn’t work.

What else do I need in order to be able to #include <SimpleSignal.h>?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
czoidocommented, Jan 12, 2021

Hi @smac89, Yes, you can use the variable CONAN_EXPORTED to check if you are running on Conan’s local cache or in user space. That way you can test your project using cmake-conan but also creating the package using Conan commands directly. I thought that for your case it was easier to explain it without making both things as you are just consuming the SimpleSignal package. I have created a complete example on how to use cmake-conan for both consuming and creating packages that maybe clears a little the explanation in the docs.

0reactions
czoidocommented, Jan 12, 2021

I’m closing this issue, please feel free to reopen if you have more questions regarding this topic.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's the proper way of using header-only library?
Traditionally you would include them in your include path, but you can also put them in your project. Including them in your project...
Read more >
Building a header-only library — Hello World | by Ryan Graham
The first is the single header structure which features an include folder at the root of the repository with a single header file...
Read more >
Header-only libraries | Advanced C++ Programming Cookbook
The benefit of header-only libraries is that they are easy to include in your project as you simply include the header and you...
Read more >
What is a header-only library and how do you use it ... - Reddit
The main header file includes the entire library implementation so if you include MyHeaderOnlyLib.h in main.cpp and build main.cpp , you also ...
Read more >
Header-only libraries
In modern C++, libraries often consist of just header files, without any source files to compile. To use such libraries, you need to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found