jgaa / restc-cpp

Modern C++ REST Client library
MIT License
605 stars 95 forks source link

Problems building in Mac #45

Closed jdiaz4517 closed 6 years ago

jdiaz4517 commented 6 years ago

Hello

Firstable thanks for a lot for all your work on this, I'm really looking forward to use it and play with it. I've been trying to build the project using instructions on: https://github.com/jgaa/restc-cpp/wiki/Building-under-macOS but when running make I'm getting a lot of errors.

I wonder if you could point me out in what the problem could be? I'm doing this in my Mac running High Sierra and with this compiler version:

-- The C compiler identification is AppleClang 9.0.0.9000039 -- The CXX compiler identification is AppleClang 9.0.0.9000039

Thanks a lot Javier

..... errors from this point onward, before this is all building ok ... In file included from /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:23: /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/helper.h:39:19: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions] for(const auto& it : src) { ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/helper.h:39:28: warning: range-based for loop is a C++11 extension [-Wc++11-extensions] for(const auto& it : src) { ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/helper.h:54:5: error: expected member name or ';' after declaration specifiers { ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/helper.h:53:11: error: expected '(' : buf{stream.str()} ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/helper.h:53:24: error: expected ';' after expression : buf{stream.str()} ^ ; In file included from /Users/jdiaz/Development/cplusplus/restc-cpp/tests/unit/AsyncSleepTests.cpp:13: In file included from /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:24: /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/Connection.h:15:19: warning: alias declarations are a C++11 extension [-Wc++11-extensions] using ptr_t = std::shared_ptr; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/Connection.h:17:10: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions] enum class Type { ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/Connection.h:22:29: warning: defaulted function definitions are a C++11 extension [-Wc++11-extensions] virtual ~Connection() = default; ^ In file included from /Users/jdiaz/Development/cplusplus/restc-cpp/tests/unit/AsyncSleepTests.cpp:13: /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:64:25: warning: alias declarations are a C++11 extension [-Wc++11-extensions] using write_buffers_t = std::vector; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:70:17: warning: defaulted function definitions are a C++11 extension [-Wc++11-extensions] Arg() = default; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:71:27: warning: defaulted function definitions are a C++11 extension [-Wc++11-extensions] Arg(const Arg&) = default; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:74:25: error: expected member name or ';' after declaration specifiers : name{use_name}, value{use_value} {} ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:84:18: warning: defaulted function definitions are a C++11 extension [-Wc++11-extensions] Auth() = default; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:85:29: warning: defaulted function definitions are a C++11 extension [-Wc++11-extensions] Auth(const Auth&) = default; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:86:18: warning: rvalue references are a C++11 extension [-Wc++11-extensions] Auth(Auth&&) = default; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:86:24: warning: defaulted function definitions are a C++11 extension [-Wc++11-extensions] Auth(Auth&&) = default; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:88:25: error: expected member name or ';' after declaration specifiers : name{authName}, passwd{authPasswd} {} ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:96:31: warning: rvalue references are a C++11 extension [-Wc++11-extensions] Auth& operator = (Auth&&) = default; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:96:37: warning: defaulted function definitions are a C++11 extension [-Wc++11-extensions] Auth& operator = (Auth&&) = default; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:103:14: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions] enum class Type { NONE, HTTP }; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:104:19: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] Type type = Type::NONE; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:108:23: warning: alias declarations are a C++11 extension [-Wc++11-extensions] using headers_t = std::map<std::string, std::string, ciLessLibC>; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:109:20: warning: alias declarations are a C++11 extension [-Wc++11-extensions] using args_t = std::deque; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:110:20: warning: alias declarations are a C++11 extension [-Wc++11-extensions] using auth_t = Auth; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:112:10: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions] enum class Type { ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:121:23: warning: alias declarations are a C++11 extension [-Wc++11-extensions] using ptr_t = std::shared_ptr; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:123:26: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] int maxRedirects = 3; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:124:30: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] int connectTimeoutMs = (1000 12); ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:125:27: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] int sendTimeoutMs = (1000 12); // For each IO operation ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:126:28: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] int replyTimeoutMs = (1000 21); // For the reply header ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:127:25: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] int recvTimeout = (1000 21); // For each IO operation ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:128:52: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] std::size_t cacheMaxConnectionsPerEndpoint = 16; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:129:41: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] std::size_t cacheMaxConnections = 128; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:130:29: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] int cacheTtlSeconds = 60; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:131:41: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] int cacheCleanupIntervalSeconds = 3; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:163:26: warning: defaulted function definitions are a C++11 extension [-Wc++11-extensions] virtual ~Request() = default; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:169:48: error: expected expression std::unique_ptr body = {}, ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:170:50: error: expected expression const boost::optional& args = {}, ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:171:56: error: expected expression const boost::optional& headers = {}, ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:172:50: error: expected expression const boost::optional& auth = {}); ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:104:21: warning: use of enumeration in a nested name specifier is a C++11 extension [-Wc++11-extensions] Type type = Type::NONE; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:74:15: error: expected '(' : name{use_name}, value{use_value} {} ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:74:24: error: expected ';' after expression : name{use_name}, value{use_value} {} ^ ; /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:74:16: warning: expression result unused [-Wunused-value] : name{use_name}, value{use_value} {} ^~~~ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:88:15: error: expected '(' : name{authName}, passwd{authPasswd} {} ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:88:24: error: expected ';' after expression : name{authName}, passwd{authPasswd} {} ^ ; /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:88:16: warning: expression result unused [-Wunused-value] : name{authName}, passwd{authPasswd} {} ^~~~ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:179:14: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions] enum class HttpVersion { ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:182:34: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] HttpVersion http_version = HttpVersion::HTTP_1_1; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:183:25: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions] int status_code = 0; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:187:24: warning: defaulted function definitions are a C++11 extension [-Wc++11-extensions] virtual ~Reply() = default; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:182:36: warning: use of enumeration in a nested name specifier is a C++11 extension [-Wc++11-extensions] HttpVersion http_version = HttpVersion::HTTP_1_1; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:267:15: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions] const auto microseconds = ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:292:22: warning: alias declarations are a C++11 extension [-Wc++11-extensions] using prc_fn_t = std::function<void (Context& ctx)>; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:296:25: warning: defaulted function definitions are a C++11 extension [-Wc++11-extensions] DoneHandler() = default; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:297:34: warning: defaulted function definitions are a C++11 extension [-Wc++11-extensions] virtual ~DoneHandler() = default; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:303:29: warning: defaulted function definitions are a C++11 extension [-Wc++11-extensions] virtual ~RestClient() = default; ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:328:9: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions] auto prom = std::make_shared<std::promise>(); ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:328:52: error: a space is required between consecutive right angle brackets (use '> >') auto prom = std::make_shared<std::promise>(); ^~

/Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:329:9: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions] auto future = prom->get_future(); ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/restc-cpp.h:332:28: error: expected expression [prom,fn,this](boost::asio::yield_context yield) { ^ In file included from /Users/jdiaz/Development/cplusplus/restc-cpp/tests/unit/AsyncSleepTests.cpp:14: /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/error.h:22:5: error: expected member name or ';' after declaration specifiers { ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/error.h:21:20: error: expected '(' , http_response{response} ^ /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/error.h:21:29: error: expected ';' after expression , http_response{response} ^ ; /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/error.h:21:21: warning: expression result unused [-Wunused-value] , http_response{response} ^~~~ In file included from /Users/jdiaz/Development/cplusplus/restc-cpp/tests/unit/AsyncSleepTests.cpp:15: In file included from /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/RequestBuilder.h:12: In file included from /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/SerializeJson.h:29: /Users/jdiaz/Development/cplusplus/restc-cpp/include/restc-cpp/RapidJsonReader.h:24:5: error: expected member name or ';' after declaration specifiers { ^ fatal error: too many errors emitted, stopping now [-ferror-limit=] 47 warnings and 20 errors generated. make[2]: [tests/unit/CMakeFiles/async_sleep_tests.dir/AsyncSleepTests.cpp.o] Error 1 make[1]: [tests/unit/CMakeFiles/async_sleep_tests.dir/all] Error 2 make: *** [all] Error 2

jgaa commented 6 years ago

It seems like you are trying to build it without C++11 language extensions. If you use cmake, you can use

set_property(TARGET tgt PROPERTY CXX_STANDARD 14) 

See https://cmake.org/cmake/help/v3.1/prop_tgt/CXX_STANDARD.html.

If use use clang directly, just add -std=c++14 on the command-line.

jdiaz4517 commented 6 years ago

Hi, thanks a lot for getting back to me. I'm not totally sure were I should do those modifications. I clone your repo and then I try to follow exactly the instructions on "Building under MacOs"

... rm -rf build mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib -DBOOST_LIBRARIES=/usr/local/opt/boost/lib -DBOOSTL_ROOT_DIR=/usr/local/opt/boost -DZLIB_INCLUDE_DIRS=/usr/local/opt/zlib/include/ -DZLIB_LIBRARIES=/usr/local/opt/zlib/lib/ .. make -j4 ctest .....

I believe the cmake ... command is using the CMakeList.txt in the root folder which it looks is setup by default to use C++ 14

if (RESTC_CPP_USE_CPP17) message(STATUS "Using C++ 17") set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17) else() message(STATUS "Using C++ 14") set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14) endif()

When you said I'm trying to build without C++11 extensions, does that mean I need to change any of the files in the cloned repo?

Thanks Javier

jgaa commented 6 years ago

I just updated cmake on my mac and ran the following commands:

brew install openssl boost zlib cmake
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/opt/openssl/lib -DBOOST_LIBRARIES=/usr/local/opt/boost/lib -DBOOSTL_ROOT_DIR=/usr/local/opt/boost -DZLIB_INCLUDE_DIRS=/usr/local/opt/zlib/include/ -DZLIB_LIBRARIES=/usr/local/opt/zlib/lib/ ..

The output was:

-- Building restc-cpp version 0.9.0
-- EXTERNAL_RAPIDJSON_INCLUDE_DIR: /Users/jgaa/src/restc-cpp/build/external-projects/installed/include/rapidjson
-- Using /Library/Developer/CommandLineTools/usr/bin/c++
-- Using C++ 14 for restc-cpp
CMake Warning at /usr/local/Cellar/cmake/3.10.2/share/cmake/Modules/FindBoost.cmake:801 (message):
  New Boost version may have incorrect or missing dependencies and imported
  targets

[Removed more warnings regarding boost]

-- Boost version: 1.66.0
-- Found the following Boost libraries:
--   system
--   program_options
--   filesystem
--   date_time
--   context
--   coroutine
--   chrono
--   log
--   thread
--   log_setup
--   regex
--   atomic
-- Using C++ 14 for url_tests
-- Using C++ 14 for json_serialize_tests
-- Using C++ 14 for json_iostream_tests
-- Using C++ 14 for http_reply_tests
-- Using C++ 14 for async_sleep_tests
-- Using C++ 14 for basic_tests
-- Using C++ 14 for readme_tests
-- Using C++ 14 for auth_tests
-- Using C++ 14 for upload_tests
-- Using C++ 14 for inserter_serializer_tests
-- Using C++ 14 for ccache_tests
-- Using C++ 14 for redirect_tests
-- Using C++ 14 for crud_tests
-- Using C++ 14 for many_connections_tests
-- Using C++ 14 for https_tests
-- Using C++ 14 for own_ioservice_tests
-- Using C++ 14 for connection_pool_instances_test
-- Using C++ 14 for proxy-tests
-- Using C++ 14 for cookie-tests
-- Using C++ 14 for logip
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/jgaa/src/restc-cpp/build

If you try this, do you see the 'Using C++ 14' lines?

jdiaz4517 commented 6 years ago

Hi

Really appreciate your time. I wasn't getting an output similar to yours from cmake... command.

I've added at the end what I was getting. So I went and started fresh, removed everything, got repo again and ran the commands you sent me, including the make command, and now all went totally ok, so once again, thanks a lot.

We have some critical code (a rest microservice getting more than 2000ops) which is currently in Java. We really need to improve performance/number of resource a lot, and one of the ideas is trying to move it to C++. We would like to use your restc-cpp and see how it goes. I will keep you informed if you don't mind.

Thanks a lot

=== below the output I was getting ======= -- The C compiler identification is AppleClang 9.0.0.9000039 -- The CXX compiler identification is AppleClang 9.0.0.9000039 -- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc -- works -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Detecting C compile features -- Detecting C compile features - done -- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Detecting CXX compile features -- Detecting CXX compile features - done -- EXTERNAL_RAPIDJSON_INCLUDE_DIR: /Users/jdiaz/Development/cplusplus/restc-cpp/build/external-projects/installed/include/rapidjson -- Using /Library/Developer/CommandLineTools/usr/bin/c++ -- Using C++ 14 -- Found ZLIB: /usr/lib/libz.dylib (found version "1.2.11") -- Found OpenSSL: /usr/local/opt/openssl/lib/libssl.dylib;/usr/local/opt/openssl/lib/libcrypto.dylib (found version "1.0.2n") -- Looking for pthread.h -- Looking for pthread.h - found -- Looking for pthread_create -- Looking for pthread_create - found -- Found Threads: TRUE -- Boost version: 1.66.0 -- Found the following Boost libraries: -- system -- program_options -- filesystem -- date_time -- context -- coroutine -- chrono -- log -- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY -- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success -- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY -- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success -- Performing Test COMPILER_HAS_DEPRECATED_ATTR -- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success -- Configuring done -- Generating done CMake Warning: Manually-specified variables were not used by the project:

BOOSTL_ROOT_DIR
BOOST_LIBRARIES

-- Build files have been written to: /Users/jdiaz/Development/cplusplus/restc-cpp/build

jgaa commented 6 years ago

If you need to optimize the performance, one approach is to ditch REST and use protobuf and C++. Google even has a RPC library for protobuf now, grpc that, that makes things a lot simpler.

But if you are stuck with REST, C++ could give a performance boost. Just make sure to profile your code, and optimize the places where most time are spent. C++ optimization is fun :)