heroiclabs / nakama-cpp

Generic C/C++ client for Nakama server.
https://heroiclabs.com/docs/cpp-client-guide
Apache License 2.0
69 stars 25 forks source link

Failing to build example for Mac #15

Closed dhruvkakadiya closed 5 years ago

dhruvkakadiya commented 5 years ago

Trying nakama-cpp client SDK for Mac and it's failing to build.

Undefined symbols for architecture x86_64:
  "_CFErrorCopyDescription", referenced from:
      (anonymous namespace)::getSSLErrorDescription(int) in libixwebsocket.a(IXSocketAppleSSL.cpp.o)
  "_CFErrorCreate", referenced from:
      (anonymous namespace)::getSSLErrorDescription(int) in libixwebsocket.a(IXSocketAppleSSL.cpp.o)
  "_CFRelease", referenced from:
      ix::SocketAppleSSL::close() in libixwebsocket.a(IXSocketAppleSSL.cpp.o)
      (anonymous namespace)::getSSLErrorDescription(int) in libixwebsocket.a(IXSocketAppleSSL.cpp.o)
  "_CFStringGetCString", referenced from:
      (anonymous namespace)::getSSLErrorDescription(int) in libixwebsocket.a(IXSocketAppleSSL.cpp.o)
  "_CFStringGetSystemEncoding", referenced from:
      (anonymous namespace)::getSSLErrorDescription(int) in libixwebsocket.a(IXSocketAppleSSL.cpp.o)
  "_SSLClose", referenced from:
      ix::SocketAppleSSL::close() in libixwebsocket.a(IXSocketAppleSSL.cpp.o)
  "_SSLCreateContext", referenced from:
      ix::SocketAppleSSL::connect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::function<bool ()> const&) in libixwebsocket.a(IXSocketAppleSSL.cpp.o)
  "_SSLHandshake", referenced from:
      ix::SocketAppleSSL::connect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::function<bool ()> const&) in libixwebsocket.a(IXSocketAppleSSL.cpp.o)
  "_SSLRead", referenced from:
      ix::SocketAppleSSL::recv(void*, unsigned long) in libixwebsocket.a(IXSocketAppleSSL.cpp.o)
  "_SSLSetConnection", referenced from:
      ix::SocketAppleSSL::connect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::function<bool ()> const&) in libixwebsocket.a(IXSocketAppleSSL.cpp.o)
  "_SSLSetIOFuncs", referenced from:
      ix::SocketAppleSSL::connect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::function<bool ()> const&) in libixwebsocket.a(IXSocketAppleSSL.cpp.o)
  "_SSLSetPeerDomainName", referenced from:
      ix::SocketAppleSSL::connect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::function<bool ()> const&) in libixwebsocket.a(IXSocketAppleSSL.cpp.o)
  "_SSLSetProtocolVersionMin", referenced from:
      ix::SocketAppleSSL::connect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::function<bool ()> const&) in libixwebsocket.a(IXSocketAppleSSL.cpp.o)
  "_SSLWrite", referenced from:
      ix::SocketAppleSSL::send(char*, unsigned long) in libixwebsocket.a(IXSocketAppleSSL.cpp.o)
  "_kCFAllocatorDefault", referenced from:
      ix::SocketAppleSSL::connect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::function<bool ()> const&) in libixwebsocket.a(IXSocketAppleSSL.cpp.o)
      (anonymous namespace)::getSSLErrorDescription(int) in libixwebsocket.a(IXSocketAppleSSL.cpp.o)
  "_kCFErrorDomainOSStatus", referenced from:
      (anonymous namespace)::getSSLErrorDescription(int) in libixwebsocket.a(IXSocketAppleSSL.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)
ninja: build stopped: subcommand failed.
Dimon4eg commented 5 years ago

Have you added libssl.a and libcrypto.a to link libraries?

dhruvkakadiya commented 5 years ago

Thank you. Looks like linking of OpenSSL and Crypto is not enough for Mac so needed to link few other libraries(related to Apple specific secure sockets) to get it compiled fine.

find_package(OpenSSL REQUIRED)
target_link_libraries(nakama-cmake-client-example PUBLIC OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(nakama-cmake-client-example PUBLIC "-framework foundation" "-framework security")
dhruvkakadiya commented 5 years ago

So probably better to link OpenSSL and Crypto libraries inside CMakeLists.txt along with if OS is Apple then link "-framework foundation" "-framework security" as well.

Dimon4eg commented 5 years ago

Fixed in master branch