Skip to content

Undefined symbols #1381

@yechentide

Description

@yechentide

Hello,
I was trying to use cpprestsdk on CLion.

I copied cmakelists and sample code from README and tutorial.
but the cmakelists didn't work:

Undefined symbols for architecture x86_64:
  "web::uri_builder::append_query_encode_impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
      web::uri_builder& web::uri_builder::append_query<char [18]>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const (&) [18], bool) in main.cpp.o
  "web::uri_builder::append_query_no_encode_impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
      web::uri_builder& web::uri_builder::append_query<char [18]>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const (&) [18], bool) in main.cpp.o
  "web::uri::uri(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
      web::http::client::http_client::request(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, pplx::cancellation_token const&) in main.cpp.o
  "web::http::details::_http_request::_http_request(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)", referenced from:
      void __gnu_cxx::new_allocator<web::http::details::_http_request>::construct<web::http::details::_http_request, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(web::http::details::_http_request*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&) in main.cpp.o
  "web::http::methods::GET[abi:cxx11]", referenced from:
      main::{lambda(Concurrency::streams::basic_ostream<unsigned char>)#1}::operator()(Concurrency::streams::basic_ostream<unsigned char>) const in main.cpp.o
  "web::uri_builder::to_string[abi:cxx11]() const", referenced from:
      main::{lambda(Concurrency::streams::basic_ostream<unsigned char>)#1}::operator()(Concurrency::streams::basic_ostream<unsigned char>) const in main.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[3]: *** [learnCppRest] Error 1
make[2]: *** [CMakeFiles/learnCppRest.dir/all] Error 2
make[1]: *** [CMakeFiles/learnCppRest.dir/rule] Error 2
make: *** [learnCppRest] Error 2

I am new in c++ and cmake. I spent two days searching for a solution.
I changed cmakelists but I got same errors.
Now the cmake file is:

cmake_minimum_required(VERSION 3.15)
project(learnCppRest)

set(CMAKE_CXX_STANDARD 17)


set(OPENSSL_ROOT_DIR /usr/local/Cellar/[email protected]/1.1.1f)
set(CPPRESTSDK_INCLUDE_DIR /usr/local/Cellar/cpprestsdk/2.10.15/include)
set(CPPRESTSDK_SOURCE_DIR /usr/local/Cellar/cpprestsdk/2.10.15/lib)
set(OPENSSL_INCLUDE_DIR /usr/local/Cellar/[email protected]/1.1.1f/include)
set(OPENSSL_SOURCE_DIR /usr/local/Cellar/[email protected]/1.1.1f/lib)
set(BOOST_INCLUDE_DIR /usr/local/Cellar/boost/1.72.0_1/include)
set(BOOST_SOURCE_DIR /usr/local/Cellar/boost/1.72.0_1/lib)


include_directories(${CPPRESTSDK_INCLUDE_DIR})
include_directories(${OPENSSL_INCLUDE_DIR})
include_directories(${BOOST_INCLUDE_DIR})

link_directories(${CPPRESTSDK_SOURCE_DIR})
link_directories(${OPENSSL_SOURCE_DIR})
link_directories(${BOOST_SOURCE_DIR})


find_package(cpprestsdk REQUIRED)

add_executable(learnCppRest main.cpp)


target_link_libraries(learnCppRest
        ${CPPRESTSDK_SOURCE_DIR}/libcpprest.2.10.dylib
        ${CPPRESTSDK_SOURCE_DIR}/libcpprest.dylib
        ${OPENSSL_SOURCE_DIR}/libssl.dylib
        ${OPENSSL_SOURCE_DIR}/libcrypto.dylib
        ${BOOST_SOURCE_DIR}/libboost_system.dylib
)

Could anyone give me any suggestions or solutions?
Thank you in advance.

my OS and IDE

  • MacOS 10.14.6
  • CLion 2019.3.4

my toolchain

  • CMake 3.15.3
    (Bundled)
  • make 3.8.1
    (/usr/bin/make)
  • gcc 9.3.0
    (/usr/local/bin/gcc)
  • g++
    (/usr/local/bin/g++)

dependencies

  • openssl 1.1.1f
    (/usr/local/Cellar/[email protected]/1.1.1f)
  • boost 1.72.0
    (/usr/local/Cellar/boost/1.72.0_1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions