Thalhammer / jwt-cpp

A header only library for creating and validating json web tokens in c++
https://thalhammer.github.io/jwt-cpp/
MIT License
864 stars 235 forks source link

[question] How to build this library on macOS #218

Closed oyljerry closed 2 years ago

oyljerry commented 2 years ago

Describe the impediment I want to use this library on macOS, But I could not use it correctly.

Trying to obtain I download master zip from repo, then follow below steps.

mkdir build && cd build
mkdir install
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./install -DJWT_DISABLE_BASE64=ON -DJWT_DISABLE_PICOJSON=OFF -DJWT_BUILD_EXAMPLES=OFF -DOPENSSL_ROOT_DIR=/Users/xxx/openssl ..
make
make install

Desktop (please complete the following information): (Include/Attach if Applicable)

Additional context After cmake and make install, the generated files in install folder (jwt-cpp and picojson). Then, I include these two folder into project, and try sample code.

#include <jwt-cpp/jwt.h>
#include <iostream>

std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
    auto decoded = jwt::decode(token);

The error is as below.

No matching function for call to 'decode'

Logs (Include/Attach if Applicable)

Click to expand log ``` -- The C compiler identification is AppleClang 12.0.0.12000032 -- The CXX compiler identification is AppleClang 12.0.0.12000032 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Found OpenSSL: /Users/xxx/openssl/lib/libcrypto.a (found suitable version "1.1.1l", minimum required is "1.0.1") -- Configuring done -- Generating done ```
prince-chrismc commented 2 years ago

Hmmm 🤔 looks good at first glance...

Can you please share your CMakeList.txt? As well as the verbose build command/output? That might give us more clues 🤞

oyljerry commented 2 years ago

Below is make install output

$ make install
Install the project...
-- Install configuration: "Release"
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/cmake/jwt-cpp-targets.cmake
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp/.DS_Store
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp/traits
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp/traits/kazuho-picojson
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp/traits/kazuho-picojson/traits.h
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp/traits/kazuho-picojson/defaults.h
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp/traits/nlohmann-json
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp/traits/nlohmann-json/traits.h
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp/traits/nlohmann-json/defaults.h
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp/traits/danielaparker-jsoncons
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp/traits/danielaparker-jsoncons/traits.h
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp/traits/danielaparker-jsoncons/defaults.h
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp/traits/boost-json
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp/traits/boost-json/traits.h
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp/traits/boost-json/defaults.h
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp/traits/defaults.h.mustache
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp/jwt.h
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/jwt-cpp/base.h
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/include/picojson/picojson.h
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/cmake/jwt-cpp-config.cmake
-- Installing: /XXX//jwt-cpp-0.6.0/build/install/cmake/jwt-cpp-config-version.cmake
prince-chrismc commented 2 years ago

I appogize, my question was not clear. Let me try again!

I wanted to know how are you building the example code? I am curious how you are getting the compilation error. What build command are you using to get it?

You posted CMake logs so I assumed (incorrectly) you were building it separately. Also you have EXAMPLES=OFF in the configure which further lead me astray.

oyljerry commented 2 years ago

Sorry, I made a mistake. When I compile, I disable DJWT_DISABLE_BASE64, so when decode, It shows No matching function for call to 'decode'.

prince-chrismc commented 2 years ago

I am glad you solved your issue!

If there is anything you can suggest to improve the example please let us know, always looking to improve ❤️