Code Monkey home page Code Monkey logo

Comments (12)

Thalhammer avatar Thalhammer commented on July 21, 2024

The error suggests that the version of OpenSSL you use does not include _EVP_sha256 and _HMAC.
Unfortunately, I don't have a Mac to test, but searching for this error it seems this is a common (and known) issue:
https://tor.stackexchange.com/questions/595/tor-compiling-error-undefined-symbols-in-libor-crypto-a

In case it is just the test cases that fail and you're not using any of the HS* algorithms in your project you might not need to change anything since the should not trigger a linker error when not used.

If you need HS256, HS384 or HS512 support it looks like your best bet is recompiling OpenSSL.

Please let me know if you solved it so I can add a note in the Readme to inform users about this.

from jwt-cpp.

DLTech21 avatar DLTech21 commented on July 21, 2024

the openssl installed by brew

from jwt-cpp.

Thalhammer avatar Thalhammer commented on July 21, 2024

@DLTech21 Make sure the version installed by brew is actually used when building and if it is, check if it contains those two symbols. I suspect it is using either the wrong library (i.e. system default, not the brew one) or the brew lib does not contain sha256 support.

I'm sorry for not being really helpful. I'll try to compile it once I have access to a Mac again but it might take until the beginning of next month and really hope to solve this issue long before this time.

from jwt-cpp.

DLTech21 avatar DLTech21 commented on July 21, 2024

solved by link compiled librarys

from jwt-cpp.

DLTech21 avatar DLTech21 commented on July 21, 2024

thx

from jwt-cpp.

Thalhammer avatar Thalhammer commented on July 21, 2024

I'll add a note to Readme and link this issue in case of somebody running into the same issue.

from jwt-cpp.

taruna789 avatar taruna789 commented on July 21, 2024

I was also facing the same issues in mu ubuntu 16.04, resolved it by Including -libssl -llibcrypto dependencies in Makefile

from jwt-cpp.

aib628 avatar aib628 commented on July 21, 2024

I was also facing the same issues in mu ubuntu 16.04, resolved it by Including -libssl -llibcrypto dependencies in Makefile

Can you make it clearly ? What should i do if use cmake, Thanks very much.

from jwt-cpp.

aib628 avatar aib628 commented on July 21, 2024

According to the article, replace brew openssl to the default successfully : https://www.zhihu.com/question/36693783

But the problem still hasn't been solved.


> (base) vmaster@vmasterdeMacBook-Pro:~/Docker/debezium/connector_sosp$ openssl version

LibreSSL 2.8.3

> (base) vmaster@vmasterdeMacBook-Pro:~/Docker/debezium/connector_sosp$ /usr/local/opt/openssl@3/bin/openssl version

OpenSSL 3.0.5 5 Jul 2022 (Library: OpenSSL 3.0.5 5 Jul 2022)

> (base) vmaster@vmasterdeMacBook-Pro:~/Docker/debezium/connector_sosp$ brew link openssl

Warning: Refusing to link macOS provided/shadowed software: openssl@3
If you need to have openssl@3 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/openssl@3/bin:$PATH"' >> ~/.profile

For compilers to find openssl@3 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@3/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@3/include"

For pkg-config to find openssl@3 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl@3/lib/pkgconfig"

> (base) vmaster@vmasterdeMacBook-Pro:~/Docker/debezium/connector_sosp$ vim /etc/profile

> (base) vmaster@vmasterdeMacBook-Pro:~/Docker/debezium/connector_sosp$ source /etc/profile

vmaster@vmasterdeMacBook-Pro:~/Docker/debezium/connector_sosp$ openssl version
OpenSSL 3.0.5 5 Jul 2022 (Library: OpenSSL 3.0.5 5 Jul 2022)

> (base) vmaster@vmasterdeMacBook-Pro:~/Docker/debezium/connector_sosp$ /usr/bin/openssl version

LibreSSL 2.8.3

The code snippet is as follows:

FIND_PACKAGE(OpenSSL)
if (${OpenSSL_FOUND})
message(${OPENSSL_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
endif ()

The output: Using OpenSSL: /usr/local/Cellar/openssl@3/3.0.5/include

> (base) vmaster@vmasterdeMacBook-Pro:~/WorkSpace/CLionProjects/jwt_creator(master)$ make

Using OpenSSL: /usr/local/Cellar/openssl@3/3.0.5/include
/usr/local/Cellar/openssl@3/3.0.5/include
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/vmaster/WorkSpace/CLionProjects/jwt_creator
Consolidate compiler generated dependencies of target libjwt
[ 16%] Built target libjwt
Consolidate compiler generated dependencies of target jwt_creator
[ 33%] Built target jwt_creator
Consolidate compiler generated dependencies of target libjwt_decrypt
[ 41%] Linking CXX shared library ../lib-test/liblibjwt_decrypt.dylib
Undefined symbols for architecture x86_64:
  "_EVP_sha256", referenced from:
      jwt::algorithm::hs256::hs256(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in jwt_decrypt.cpp.o
  "_HMAC", referenced from:
      jwt::algorithm::hmacsha::sign(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::error_code&) const in jwt_decrypt.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib-test/liblibjwt_decrypt.dylib] Error 1
make[1]: *** [test/CMakeFiles/libjwt_decrypt.dir/all] Error 2
make: *** [all] Error 2

from jwt-cpp.

prince-chrismc avatar prince-chrismc commented on July 21, 2024

The quiet old CMake 🙈

I would strongly recommend using targets instead like

target_link_libraries(jwt-cpp INTERFACE OpenSSL::SSL OpenSSL::Crypto)

Should look like this

find_package(OpenSSL REQUIRED)

add_executable(your_app_here main.cpp)
target_link_libraries(your_app_here OpenSSL::SSL OpenSSL::Crypto)

from jwt-cpp.

aib628 avatar aib628 commented on July 21, 2024

LibreSSL 3.5.3 has the same problem on mac:

> (base) vmaster@vmasterdeMacBook-Pro:~/WorkSpace/CLionProjects/jwt_creator(master)$ openssl version

LibreSSL 3.5.3

> (base) vmaster@vmasterdeMacBook-Pro:~/WorkSpace/CLionProjects/jwt_creator(master)$ cmake .

Using OpenSSL: /usr/local/Cellar/libressl/3.5.3/include
/usr/local/Cellar/libressl/3.5.3/include
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/vmaster/WorkSpace/CLionProjects/jwt_creator
(base) vmaster@vmasterdeMacBook-Pro:~/WorkSpace/CLionProjects/jwt_creator(master)$ make
Consolidate compiler generated dependencies of target libjwt
[ 16%] Built target libjwt
Consolidate compiler generated dependencies of target jwt_creator
[ 33%] Built target jwt_creator
Consolidate compiler generated dependencies of target libjwt_decrypt
[ 41%] Building CXX object test/CMakeFiles/libjwt_decrypt.dir/jwt_decrypt.cpp.o
[ 50%] Linking CXX shared library ../lib-test/liblibjwt_decrypt.dylib
Undefined symbols for architecture x86_64:
  "_EVP_sha256", referenced from:
      jwt::algorithm::hs256::hs256(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >) in jwt_decrypt.cpp.o
  "_HMAC", referenced from:
      jwt::algorithm::hmacsha::sign(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::error_code&) const in jwt_decrypt.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [lib-test/liblibjwt_decrypt.dylib] Error 1
make[1]: *** [test/CMakeFiles/libjwt_decrypt.dir/all] Error 2
make: *** [all] Error 2

from jwt-cpp.

aib628 avatar aib628 commented on July 21, 2024

The quiet old CMake 🙈

I would strongly recommend using targets instead like

target_link_libraries(jwt-cpp INTERFACE OpenSSL::SSL OpenSSL::Crypto)

Should look like this

find_package(OpenSSL REQUIRED)

add_executable(your_app_here main.cpp)
target_link_libraries(your_app_here OpenSSL::SSL OpenSSL::Crypto)

Thanks ! but some error occur as follows when using targets instead, what's other should i do ?

(base) 
> vmaster@vmasterdeMacBook-Pro:~/WorkSpace/CLionProjects/jwt_creator(master)$ cmake .

-- Configuring done
-- Generating done
-- Build files have been written to: /Users/vmaster/WorkSpace/CLionProjects/jwt_creator

> (base) vmaster@vmasterdeMacBook-Pro:~/WorkSpace/CLionProjects/jwt_creator(master)$ make

Consolidate compiler generated dependencies of target libjwt
[  8%] Building CXX object src/CMakeFiles/libjwt.dir/jwt_creator.cpp.o
In file included from /Users/vmaster/WorkSpace/CLionProjects/jwt_creator/src/jwt_creator.cpp:1:
/Users/vmaster/WorkSpace/CLionProjects/jwt_creator/src/../include/jwt-cpp/jwt.h:15:10: fatal error: 'openssl/ec.h' file not found
#include <openssl/ec.h>
         ^~~~~~~~~~~~~~
1 error generated.
make[2]: *** [src/CMakeFiles/libjwt.dir/jwt_creator.cpp.o] Error 1
make[1]: *** [src/CMakeFiles/libjwt.dir/all] Error 2
make: *** [all] Error 2

The sub cmake snippet look like this (by copy jwt-cpp includes and using include_directories command):

find_package(OpenSSL REQUIRED)
include_directories(../include) # jwt-cpp includes, or using command: find_package(jwt-cpp REQUIRED)

add_executable(jwt_creator jwt_creator.cpp)
target_link_libraries(jwt_creator INTERFACE LibreSSL::TLS)

When using find_package(jwt-cpp REQUIRED)

> (base) vmaster@vmasterdeMacBook-Pro:~/WorkSpace/CLionProjects/jwt_creator(master)$ cmake .

-- Configuring done
-- Generating done
-- Build files have been written to: /Users/vmaster/WorkSpace/CLionProjects/jwt_creator

> (base) vmaster@vmasterdeMacBook-Pro:~/WorkSpace/CLionProjects/jwt_creator(master)$ make

[  8%] Building CXX object src/CMakeFiles/libjwt.dir/jwt_creator.cpp.o
/Users/vmaster/WorkSpace/CLionProjects/jwt_creator/src/jwt_creator.cpp:1:10: fatal error: 'jwt-cpp/jwt.h' file not found
#include <jwt-cpp/jwt.h>
         ^~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [src/CMakeFiles/libjwt.dir/jwt_creator.cpp.o] Error 1
make[1]: *** [src/CMakeFiles/libjwt.dir/all] Error 2
make: *** [all] Error 2

The sub cmake snippet look like this (by find_package):

find_package(OpenSSL REQUIRED)
find_package(jwt-cpp REQUIRED)

add_executable(jwt_creator jwt_creator.cpp)
target_link_libraries(jwt_creator INTERFACE LibreSSL::TLS jwt-cpp::jwt-cpp)

from jwt-cpp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.