Skip to content

using httplib cmake target #421

Closed
Closed

Description

@guteksan

Hi,
I am having a problem with linking httplib library to my project.
I have built httplib and installed it in a certain destination

My CMakeList.txt contains:

find_package(httplib CONFIG REQUIRED)
...
add_executable(${PROJECT_NAME} ${SRC})
target_link_libraries(${PROJECT_NAME} PUBLIC httplib)

This works, and the Cmake cache contains valid entry for httplib_DIR where the httplibConfig.cmake is located. But when I try to compile my project, it can't find the httplib.h, which I include. I looked into httplibConfig.cmake and there is created an INTERFACE target httplib (without any namespace), so I believe linking targets it the way I did should be enough to pass all directories. Could you please point out what is missing?

Activity

  1. yhirose commented on Apr 9, 2020

    @yhirose
    Owner

    @guteksan, thank you for the feedback. Did you install httplib via CMakeLists.txt in this project? If so, this CMakeLists.txt has been contributed by other user, and I am not familiar to what it actually do (, even I am thinking of removing the file from this project).

    Since this library is a 'header-only' library, it doesn't need to link anything. So once you manually copy httplib.h to one of include directories in your system, it much be compiled without any other treatment.

    Hope it help!

  2. guteksan commented on Apr 9, 2020

    @guteksan
    Author

    Hi, @yhirose , thank you for prompt reply.
    Yes, I did use CMakeLists.txt from this project to build and install the library. It went smooth, so I thought it is the right way,
    I know that header only libraries do not need to be linked, anyway I always prefered to separate my original code from the 3rd party dependencies, and using targets installed in the system is a nice way to do it. You might want to have a look at the Eigen library, which is also header only and allows to be used as targets in own projects.

  3. yhirose commented on Apr 10, 2020

    @yhirose
    Owner

    @guteksan, if "It went smooth, so I thought it is the right way" is true, what do you think causes the problem, in CMakeLists.txt in cpp-httplib, or the one in your project?

    Since I don't need the CMakeLists.txt at all and even tested it, I am tending to remove it from this repo unless it doesn't cause any problem...

  4. PixlRainbow commented on Apr 10, 2020

    @PixlRainbow
    Contributor

    Header only libraries on cmake are not linked against. Instead target_include_directory is used with the package directory.

  5. guteksan commented on Apr 10, 2020

    @guteksan
    Author

    @PixlRainbow: not exactly. I am not talking about linking in a proper sense, but about linking in a cmake buildsystem sense. Cmake has a concept of targets which combine information about both libs and include directiories, and the proper way of adding the dependency to a target is by: target_link_libraries, even if this is header only library. CMakeLists.txt attached to a project created a target named httplib, so that method should be used. Out of curiosity I checked if target_include_directiories will work on httplib target, but it didn't.

  6. yhirose commented on Apr 11, 2020

    @yhirose
    Owner

    @guteksan, if the current CMakeLists.txt has the problem, I'll get rid of it from this project because I don't use it anyway and I am not planning to maintain it. I would like to avoid confusing to the users.

    If you think it's still useful and find the cause of the problem, please submit a pull request. Of course, that would be the best for me! Thanks for your understanding.

  7. added a commit that references this issue on May 2, 2020
    8613e7b
  8. sum01 commented on May 9, 2020

    @sum01
    Contributor

    Could you consider bringing the file back? Having a Cmake file available is nice, even for header-only. It also affects the Conan package (at least future versions).

    The problem was probably where it installed to. For example, it was installing to /usr/include/httplib/httplib.h on Linux, but I'm assuming the OP was doing #include <httplib.h>. I personally tested v0.5.9, and it worked as-is with only a change to #include <httplib/httplib.h>.

    If you wish, I could submit a fix so it's just #include <httplib.h>, as well as some improvements upon the file, considering the file is missing some important things (opt. deps like openssl or zlib, threads, versioning).

  9. added 2 commits that reference this issue on May 10, 2020
    d4b28cc
    7169750
  10. added a commit that references this issue on May 19, 2020
    80aa185
  11. added a commit that references this issue on May 19, 2020
    9505a76
  12. added 2 commits that reference this issue on May 2, 2023
    e59ffaa
    8af9bd6
  13. added a commit that references this issue on Jul 23, 2024
    8674555
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions