You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
@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.
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.
@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...
@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.
@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.
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).
Activity
yhirose commentedon Apr 9, 2020
@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!
guteksan commentedon Apr 9, 2020
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.
yhirose commentedon Apr 10, 2020
@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...
PixlRainbow commentedon Apr 10, 2020
Header only libraries on cmake are not linked against. Instead
target_include_directoryis used with the package directory.guteksan commentedon Apr 10, 2020
@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 namedhttplib, so that method should be used. Out of curiosity I checked iftarget_include_directiorieswill work onhttplibtarget, but it didn't.yhirose commentedon Apr 11, 2020
@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.
Removed CMakeLists.txt. (Fix #421)
sum01 commentedon May 9, 2020
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.hon 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).Revert "Removed CMakeLists.txt. (Fix yhirose#421)"
Fix wrong install path of header in Cmake
Revert "Removed CMakeLists.txt. (Fix yhirose#421)"
Bringing Cmake back (#470)
Removed CMakeLists.txt. (Fix yhirose#421)
Bringing Cmake back (yhirose#470)
Removed CMakeLists.txt. (Fix yhirose#421)