Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac compile error - undefined symbols #6

Closed
DLTech21 opened this issue Sep 22, 2018 · 12 comments
Closed

Mac compile error - undefined symbols #6

DLTech21 opened this issue Sep 22, 2018 · 12 comments
Labels

Comments

@DLTech21
Copy link

while compiling on mac, comes error
Undefined symbols for architecture x86_64:
"_EVP_sha256", referenced from:
jwt::algorithm::hs256::hs256(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >) in main.cpp.o
"_HMAC", referenced from:
jwt::algorithm::hmacsha::sign(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&) const in main.cpp.o
ld: symbol(s) not found for architecture x86_64

@Thalhammer
Copy link
Owner

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.

@DLTech21
Copy link
Author

the openssl installed by brew

@Thalhammer
Copy link
Owner

Thalhammer commented Sep 22, 2018

@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.

@DLTech21
Copy link
Author

solved by link compiled librarys

@DLTech21
Copy link
Author

thx

@Thalhammer
Copy link
Owner

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

@taruna789
Copy link

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

@aib628
Copy link

aib628 commented Aug 5, 2022

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.

@aib628
Copy link

aib628 commented Aug 5, 2022

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

@prince-chrismc
Copy link
Collaborator

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)

@prince-chrismc prince-chrismc changed the title Mac compile error Mac compile error - undefined symbols Aug 5, 2022
@aib628
Copy link

aib628 commented Aug 5, 2022

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

@aib628
Copy link

aib628 commented Aug 5, 2022

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants