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

cannot compile sample on OSX #458

Open
dcp12345678 opened this issue May 31, 2017 · 9 comments
Open

cannot compile sample on OSX #458

dcp12345678 opened this issue May 31, 2017 · 9 comments

Comments

@dcp12345678
Copy link

dcp12345678 commented May 31, 2017

I'm on OSX El Capitan, I did an install using the instructions located here.

$ brew install cpprestsdk

I copied the sample code from here and tried to compile it, but get this error:

usr/local/include/boost/asio/ssl/detail/openssl_types.hpp:20:10: fatal error: 'openssl/conf.h' file not found
#include <openssl/conf.h>

I tried adding -I and -L flags to the g++ arguments like this:
g++ -std=c++11 test.cpp -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib

But then I get a bunch more errors: (the first few are shown below)

Undefined symbols for architecture x86_64:
  "_CONF_modules_unload", referenced from:
      boost::asio::ssl::detail::openssl_init_base::do_init::~do_init() in test-72b3e4.o
  "_CRYPTO_cleanup_all_ex_data", referenced from:
      boost::asio::ssl::detail::openssl_init_base::do_init::~do_init() in test-72b3e4.o
  "_CRYPTO_num_locks", referenced from:
      boost::asio::ssl::detail::openssl_init_base::do_init::do_init() in test-72b3e4.o

I'm not sure how to proceed from here. Thanks for any help.

@bubbercn
Copy link

I met the same problem. What I did is to explicitly link to the openssl libs to solve this. Actually, in order to make the sample code work, I have to link to a bunch of libs from boost as well. I deem this is problem of cpprest. For sure, itself has dependencies on openssl and boost, but the sample code clearly does not rely on them directly. Why including a head file of cpprest would require me to link to openssl and boost explicitly?

@ThorstenBux
Copy link

ThorstenBux commented Jun 14, 2017

I you use VisualStudio Code for macOS this configuration worked for me:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "g++",
    "isShellCommand": true,
    "args": ["-o test","-Wall","-std=gnu++0x", "-stdlib=libc++", 
            "-I/usr/local/Cellar/cpprestsdk/2.9.1/include/",
            "-I/usr/local/Cellar/boost/1.64.0_1/include/",
            "-I/usr/local/Cellar/openssl/1.0.2l/include/", 
            "-L/usr/local/Cellar/openssl/1.0.2l/lib/",
            "-L/usr/local/Cellar/cpprestsdk/2.9.1/lib/",
            "-L/usr/local/Cellar/boost/1.64.0_1/lib/",
            "-lssl","-lcrypto", "-lcpprest", "-lboost_system", "-lboost_thread-mt", "-lboost_chrono-mt",
            "-g","casablanca_client.cpp"],
    "showOutput": "always",
    "echoCommand": true
}

to run the HTTP_Client example

@cshung
Copy link
Member

cshung commented Oct 16, 2019

My apology to reactivate this rather old issue, the build is failing again with the macOS Catalina (Version 10.15). @BillyONeal

Here is what I did:

brew install cpprestsdk
mkdir ./build
cd ./build
cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DOPENSSL_LIBRARIES=/usr/local/Cellar/openssl/1.0.2s/lib ..
make

Here is my CMakeLists.txt

cmake_minimum_required(VERSION 3.7)
project(main)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(cpprestsdk REQUIRED)

add_executable(main main.cpp)
target_link_libraries(main PRIVATE cpprestsdk::cpprest)

It appears that

and here is my main.cpp

#include <cpprest/http_client.h>
#include <cpprest/filestream.h>

using namespace utility;                    // Common utilities like string conversions
using namespace web;                        // Common features like URIs.
using namespace web::http;                  // Common HTTP functionality
using namespace web::http::client;          // HTTP client features
using namespace concurrency::streams;       // Asynchronous streams

int main(int argc, char* argv[])
{
    auto fileStream = std::make_shared<ostream>();

    // Open stream to output file.
    pplx::task<void> requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)
    {
        *fileStream = outFile;

        // Create http_client to send the request.
        http_client client(U("http://www.bing.com/"));

        // Build request URI and start the request.
        uri_builder builder(U("/search"));
        builder.append_query(U("q"), U("cpprestsdk github"));
        return client.request(methods::GET, builder.to_string());
    })

    // Handle response headers arriving.
    .then([=](http_response response)
    {
        printf("Received response status code:%u\n", response.status_code());

        // Write response body into the file.
        return response.body().read_to_end(fileStream->streambuf());
    })

    // Close the file stream.
    .then([=](size_t)
    {
        return fileStream->close();
    });

    // Wait for all the outstanding I/O to complete and handle any exceptions
    try
    {
        requestTask.wait();
    }
    catch (const std::exception &e)
    {
        printf("Error exception:%s\n", e.what());
    }

    return 0;
}

And I have got this weirdo errors:

[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
make[2]: *** No rule to make target `/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/CoreFoundation.framework', needed by `main'.  Stop.
make[1]: *** [CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2

@EdSwArchitect
Copy link

I just received this today after a MacOS update to Catalina.
I have the same error as cshung.

@EdSwArchitect
Copy link

This is probably the problem:

https://gitlab.kitware.com/cmake/cmake/issues/19824

@Clovel
Copy link
Contributor

Clovel commented Apr 5, 2020

Has this been fixed ?

@BillyONeal
Copy link
Member

Not as far as I know.

@EdSwArchitect
Copy link

I moved on, so I can't answer.

@domingguss
Copy link

domingguss commented Jul 15, 2020

I did this and that worked

brew install openssl
cd /usr/local/include 
ln -s ../opt/openssl/include/openssl .

taken from https://www.anintegratedworld.com/mac-osx-fatal-error-opensslsha-h-file-not-found/

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

No branches or pull requests

8 participants