how to use find_package(cpprestsdk REQUIRED) in CMakeLists.txt
ubuntu 16.4 LTS install cpprestsdk use: sudo apt-get install libcpprest-dev
write "find_package(cpprestsdk REQUIRED)" to the CMakeLists.txt,there some build error: "By not providing "Findcpprestsdk.cmake" in CMAKE_MODULE_PATH this project"
how to write the "Findcpprestsdk.cmake" file,is any example already exists on ubuntu?
It may be an issue with the naming of the C++ REST SDK CMake project vs module. Have you tried the following?
find_package(cpprestsdk REQUIRED NAMES cpprestsdk cpprest)
try with this: find_package(cpprestsdk REQUIRED)
After you install the library you must heve this files:
cpprestsdk-targets.cmake cpprestsdk-config.cmake cpprestsdk-targets-release.cmake
I am also having the same find package error when using the version in apt
I didn't tried with the package coming from apt... I built cpprestsdk and installed in my pc.
I had the same problem, but as mentioned by @garethsb-sony, the suggestion did the trick for me. However, i acquired packages through vcpkg and passing -DCMAKE_TOOLCHAIN_FILE=<path to vcpkg>\vcpkg\scripts\buildsystems\vcpkg.cmake for cmake was also necessary.
I'm running into the same issue on an Ubuntu Docker image - I'm trying to set up a reproducable 32 bit build environment for Linux and this library just isn't playing well with Linux at all!
Are there also any plans to update this wiki page because it doesn't work on a blank Ubuntu image. I tried using apt get too and that didn't work either.
Here's my Dockerfile and cmake command that's executed inside the container.
What's the issue? I'm using cpprestsdk both on Linux machines and containers compiling for x86, x64 and arm architectures without any issue. Can you put some logs and explain better what is going wrong?
@elvisdukaj it just won't get past the cmake .. stage, claiming it can't find cpprestsdk, I even tried the NAMES edit suggested by @garethsb-sony and that just added more missing search queries to the error:
CMake Error at CMakeLists.txt:16 (find_package):
Could not find a package configuration file provided by "cpprestsdk" with
any of the following names:
cpprestsdkConfig.cmake
cpprestsdk-config.cmake
cpprestConfig.cmake
cpprest-config.cmake
I don't really know what else to do other than apt install -y libcpprest-dev do I need to manually point cmake to the cpprest installation directory? If so, where is that?
I should add that one of the requirements for my project is that it builds to 32 bit, so I have -m32 in the CMAKE_CXX_FLAGS if that makes a difference. I've been building the Windows version fine with 32 bit mode and it has been running in my host application fine.
@Southclaws The version coming with apt-get don't install cmake files! You need to compile it by yourself... If you need to build a 32-bit version on a 64-bit host, my suggestion is to create a 32-bit container and build from the container... Give a look here: https://www.ubuntu.com/containers/lxd
It might an issue with your CMakeLists file, @Southclaws. You have to define your cmake project first with project (foo) and then call the find_package command. See the cmake lists file code example at cpprestsdk github homepage.
@elvisdukaj ah okay, I didn't know that, I'll try building from source again (I failed already, but that's probably a question for stackoverflow rather than here)
@sarunassarakojis already got a project and all the standard CMake stuff set up, my project is actually building fine on Windows already, but thanks for the reply!
Try find_library(cpprestsdk-lib cpprest) message(STATUS "cpprestsdk-lib = ${cpprestsdk-lib}") gives -- cpprestsdk-lib = /usr/lib/x86_64-linux-gnu/libcpprest.so
What's the issue? I'm using cpprestsdk both on Linux machines and containers compiling for x86, x64 and arm architectures without any issue. Can you put some logs and explain better what is going wrong?
Hi,
Currently we are trying to install cpprest/casablanca on RHEL 6.9 but we are not successful. We also dont have root access. Could you please provide us the steps to install it with root access and also without root access ? It is also not in source list of our RHEL version.
I have the same issue. I installed libcpprest-dev on Ubuntu 18.04 and have the following in my CMakeLists.txt:
find_package(cpprestsdk REQUIRED)
I get a similar error:
CMake Error at CMakeLists.txt:19 (find_package):
By not providing "Findcpprestsdk.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"cpprestsdk", but CMake did not find one.
Could not find a package configuration file provided by "cpprestsdk" with
any of the following names:
cpprestsdkConfig.cmake
cpprestsdk-config.cmake
Add the installation prefix of "cpprestsdk" to CMAKE_PREFIX_PATH or set
"cpprestsdk_DIR" to a directory containing one of the above files. If
"cpprestsdk" provides a separate development package or SDK, be sure it has
been installed.
If I search for cpprestsdk-config.cmake, there is a hit on my system:
$ sudo updatedb
$ locate cpprestsdk-config.cmake
/usr/lib/x86_64-linux-gnu/cmake/cpprestsdk-config.cmake
I'm playing around with the CMAKE variables (e.g. CMAKE_MODULE_PATH) to try and get this file found. No luck so far.
You might have a look on my fork (https://github.com/EdgarWahn/cpprestsdk). I added some of the files needed to be able to import the project with find_package. Feel free to drop me a note, my target is to have the changes backported to the main project (I just touched makefiles, not code).
I now understand the problem. When installing from the Ubuntu packages, the config.cmake file ends up here:
/usr/lib/x86_64-linux-gnu/cmake/cpprestsdk-config.cmake
Unfortunately, this doesn't match any of the paths that cmake will naturally search. This page describes the search order and you can see that the files are almost in the right place. Any of the following paths would have been acceptable:
/usr/lib/x86_64-linux-gnu/cmake/cpprestsdk/cpprestsdk-config.cmake
/usr/lib/x86_64-linux-gnu/cpprestsdk/cpprestsdk-config.cmake
/usr/lib/x86_64-linux-gnu/cpprestsdk/cmake/cpprestsdk-config.cmake
I've worked around this by specifying cpprestsdk_DIR in my CMakeLists.txt file:
set(cpprestsdk_DIR /usr/lib/${CMAKE_LIBRARY_ARCHITECTURE}/cmake/)
On Ubuntu 16.04 LTS, there are no CMake config packages installed with the libcpprest-dev (2.8.0-2). You can see the files installed in the file list: https://packages.ubuntu.com/xenial/amd64/libcpprest-dev/filelist
On Ubuntu 18.04, libcpprest-dev (2.10.2-6) is installed with CMake config files. You can see those CMake files installed in file list: https://packages.ubuntu.com/bionic/amd64/libcpprest-dev/filelist
/usr/lib/x86_64-linux-gnu/cmake/cpprestsdk-config.cmake
/usr/lib/x86_64-linux-gnu/cmake/cpprestsdk-targets-none.cmake
/usr/lib/x86_64-linux-gnu/cmake/cpprestsdk-targets.cmake
PS: I just tried to build from source and it works for git tag v2.10.9 on Ubuntu 16.04 lts.
Just come across with the same issue on Ubuntu 18.04 and cpprestsdk 2.10. As dmjones https://github.com/Microsoft/cpprestsdk/issues/686#issuecomment-440622042 mentioned, solved by wrapping the .cmake files with folder cpprestsdk, and add a new line in cpprestsdk-targets.cmake like below.
# Compute the installation prefix relative to this file.
get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH)
# Use original install prefix when loaded through a
# cross-prefix symbolic link such as /lib -> /usr/lib.
get_filename_component(_realCurr "${_IMPORT_PREFIX}" REALPATH)
get_filename_component(_realOrig "/usr/lib/x86_64-linux-gnu/cmake" REALPATH)
if(_realCurr STREQUAL _realOrig)
set(_IMPORT_PREFIX "/usr/lib/x86_64-linux-gnu/cmake")
endif()
unset(_realOrig)
unset(_realCurr)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
# Backward one more layer, since wrapping it in another folder.
get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)
if(_IMPORT_PREFIX STREQUAL "/")
set(_IMPORT_PREFIX "")
endif()
This is an alternative way to resolve the issue. Personally think that they really should put these .cmake files in it own folder, instead of dumping them in.
Workaround for Ubuntu
cmake . -DCMAKE_PREFIX_PATH=/usr/lib/x86_64-linux-gnu/cmake
Hey there. This one works for me (Ubuntu 18.04):
find_library(cpprest REQUIRED)
#add_executable ...
target_link_libraries(project PRIVATE cpprest)
Seems like Ubuntu maintainers has fixed this. However it's not currently available in the stable branch https://bugs.launchpad.net/ubuntu/+source/cpprest/+bug/1838826
Building yourself fixes this
22 apt-get install g++ git libboost-atomic-dev libboost-thread-dev libboost-system-dev libboost-date-time-dev libboost-regex-dev libboost-filesystem-dev libboost-random-dev libboost-chrono-dev libboost-serialization-dev libwebsocketpp-dev openssl libssl-dev ninja-build
23 git clone https://github.com/Microsoft/cpprestsdk.git casablanca
24 cd casablanca
25 mkdir build.debug
26 cd build.debug
27 cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Debug
28 ninja
29 ninja install