Search code examples
c++httpclientbuild-error

http client in proxygen?


hi i am using proxygen by facebook to create a simple hhtpclient . i am trying to run their default httpclient example. I am using the following command to build it:

 g++ -std=c++11 -o my_echo   CurlClient.o CurlClientMain.o -lproxygenhttpserver -lfolly -lglog -lgflags -pthread

but i am getting the following error:

CurlClient.o: In function `CurlService::CurlClient::connectSuccess(proxygen::HTTPUpstreamSession*)':
/home/kshitij/proxygen/httpclient/samples/curl/CurlClient.cpp:69: undefined reference to `proxygen::HTTPUpstreamSession::newTransaction(proxygen::HTTPTransactionHandler*)'
CurlClientMain.o: In function `main':
/home/kshitij/proxygen/httpclient/samples/curl/CurlClientMain.cpp:91: undefined reference to `proxygen::HTTPConnector::HTTPConnector(proxygen::HTTPConnector::Callback*, folly::HHWheelTimer*)'
/home/kshitij/proxygen/httpclient/samples/curl/CurlClientMain.cpp:102: undefined reference to `proxygen::HTTPConnector::connect(folly::EventBase*, folly::SocketAddress const&, std::chrono::duration<long, std::ratio<1l, 1000l> >, std::map<folly::AsyncSocket::OptionKey, int, std::less<folly::AsyncSocket::OptionKey>, std::allocator<std::pair<folly::AsyncSocket::OptionKey const, int> > > const&, folly::SocketAddress const&)'
/home/kshitij/proxygen/httpclient/samples/curl/CurlClientMain.cpp:91: undefined reference to `proxygen::HTTPConnector::~HTTPConnector()'
/home/kshitij/proxygen/httpclient/samples/curl/CurlClientMain.cpp:99: undefined reference to `proxygen::HTTPConnector::connectSSL(folly::EventBase*, folly::SocketAddress const&, std::shared_ptr<folly::SSLContext> const&, ssl_session_st*, std::chrono::duration<long, std::ratio<1l, 1000l> >, std::map<folly::AsyncSocket::OptionKey, int, std::less<folly::AsyncSocket::OptionKey>, std::allocator<std::pair<folly::AsyncSocket::OptionKey const, int> > > const&, folly::SocketAddress const&, std::string const&)'
/home/kshitij/proxygen/httpclient/samples/curl/CurlClientMain.cpp:91: undefined reference to `proxygen::HTTPConnector::~HTTPConnector()'
collect2: error: ld returned 1 exit status

what could be the possible error. correct me if i am building it the wrong way.


Solution

  • g++ -std=c++11 -o my_echo CurlClient.o CurlClientMain.o HttpUpstreamSession.o -lproxygenhttpserver -lfolly -lglog -lgflags -pthread

    The HttpUpstreamSession.h include is referenced but the implementation is defined in its .cpp in the same directory. You need to either build the .cpp or use the .o file in your build.