cpprestsdk: Undefined symbols for architecture x86_64

廉价感情. 提交于 2019-12-06 05:48:50
Amazing Grace

The missing symbol names was due to a missing library. The necessary CPPFLAGS and LDFLAGS are:

CPPFLAGS = -stdlib=libc++
LDFLAGS = -lcpprest -lboost_system -lboost_thread-mt -lboost_chrono-mt -lssl -lcrypto

Thanks so much for everyone's help.

jww

Original Question:

  "web::uri_builder::append_path(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)", referenced from:
      std::__1::__function::__func<main::$_0, std::__1::allocator<main::$_0>, pplx::task<web::http::http_response> (Concurrency::streams::basic_ostream<unsigned char>)>::operator()(Concurrency::streams::basic_ostream<unsigned char>&&) in webclient.cpp.o
  "web::uri_builder::append_query(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bool)", referenced from:
      web::uri_builder& web::uri_builder::append_query<char [37]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [37], bool) in webclient.cpp.o
  "web::uri_builder::to_string()", referenced from:
      std::__1::__function::__func<main::$_0, std::__1::allocator<main::$_0>, pplx::task<web::http::http_response> (Concurrency::streams::basic_ostream<unsigned char>)>::operator()(Concurrency::streams::basic_ostream<unsigned char>&&) in webclient.cpp.o
  "web::uri::encode_impl(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::function<bool (int)> const&)", referenced from:
      web::uri_builder& web::uri_builder::append_query<char [37]>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const (&) [37], bool) in webclient.cpp.o
  ...

The ::__1 is LLVM's anonymous namespace. What you see above is a symptom of mixing and matching runtimes. I.e., inconsistent use of -stdlib=XXX.

You need to build everything with GNU's gear and -stlib=libstdc++; or you need to build everything with LLVM's gear and -stdlib=libc++.

What I found works best to avoid user problems and questions is to always use LLVM's gear on OS X and iOS. I.e., always use -stdlib=libc++.


Updated Question:

Undefined symbols for architecture x86_64:
  "boost::this_thread::interruption_point()", referenced from:
      boost::condition_variable::wait(boost::unique_lock<boost::mutex>&) in webclient.cpp.o
      boost::condition_variable::do_wait_until(boost::unique_lock<boost::mutex>&, timespec const&) in webclient.cpp.o
  "boost::chrono::steady_clock::now()", referenced from:
      pplx::details::event_impl::wait(unsigned int) in webclient.cpp.o
  "boost::chrono::system_clock::now()", referenced from:
      pplx::details::event_impl::wait(unsigned int) in webclient.cpp.o
  "boost::detail::get_current_thread_data()", referenced from:
      boost::detail::interruption_checker::interruption_checker(_opaque_pthread_mutex_t*, _opaque_pthread_cond_t*) in webclient.cpp.o
ld: symbol(s) not found for architecture x86_64

For the updated question, see Using and building the library in the Boost user guide. You have to build Boost with threading support (does Brew do that?), and you have to link to the Boost threading library (is CMake doing that?).

I don't use Boost or CMake, so I can't take you any further. Sorry about that.


set(OPT_CPPFLAGS "-I/usr/local/opt/openssl/include -I/usr/local/opt/libiconv/include")

I'm no CMake expert, but this could be problematic, too. CPPFLAGS is the flags for the C preprocessor. They may or may not be added to the CFLAGS and CXXFLAGS.

You should definitely call-out the same flags for CFLAGS and CXXFLAGS just in case. If this were an Autotools project, then I would change the should to a must. But like I said, I'm no CMake expert by any strecth of the imagination.


And one final note... You can't use CMake to build OpenSSL. You have to configure an build it yourself. Once installed, you can reference the installed OpenSSL in a find-openssl.cmake type fashion.

The reasons are not readily apprent... OpenSSL's Configure script sets up some important settings that are used later in the build process. The two most important files for the settings are <opensslconf.h> and <bn.h>.

You can also get an impressive speed improvement (2x to 4x) for Diffie-Hellman and Elliptic Curves on Intel-based x86_64 machines by Configureing with enable-ec_nistp_64_gcc_128.

Marshall Conover

It looks like this may be the same issue you have, with the answer being link against -lcrypto.

Edit: Your problem is that you're trying to build a program that needs to be linked against other "libraries" - that is, other pieces of code that are usually pre-compiled - that are somewhere on your system, and which define "symbols," which is basically another way of saying variables or function names.

You let the compiler know which libraries you need by including arguments to the compile command that signify what you need to be linked with - in this case, your first few issues went away because you linked with -lcrypto, and from then on your code was able to find the 'symbols' - that is, variables and function names - that were previously 'undefined.'

For the rest of your issues, where you added 'lcrypto,' try using the arguments from this wiki on building cpprestsdk on Linux. The flags appear to be:

-lboost_system -lssl -lcpprest -lboost_chrono

Last, but not least, have you follow the instructions for building this software on mac OSX on their site? It might save you a lot of pain! :)

Edit: added a few more.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!