问题
I am using POCO library 1.6.0 on OS X 10.10 and XCode 6.1.1 for building a mac application.
I have compiled it for static linking using the following configuration:
./configure --omit=Data/ODBC,MonoDB,Data/MySQL,Data/SQLite --config=Darwin64-clang-libc++ --static
This results in successful compilation and produces .a files.
I have linked the libraries in XCode under linked frameworks and libraries.
The app runs successfully.
Questions:
However on execution of Poco::Net::HTTPRequest to http://example.org, it fails with error : Net Exception Address family not supported. There is a closed issue here as well: https://github.com/pocoproject/poco/issues/657.
This happens only when the Build Configuration is set to "Debug" and not "Release" which is strange.
Here is the code:
void test(){
Poco::JSON::Object result;
result.set("error", "0");
result.set("errorMessage","");
result.set("response","");
result.set("success", "true");
try {
Poco::URI uri("http://example.org/?time=12345");
Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_GET,uri.getPath(), Poco::Net::HTTPMessage::HTTP_1_1);
req.set("User-Agent","Chrome/3.2");
session.sendRequest(req); // sends request, returns open stream
// Get response
Poco::Net::HTTPResponse res;
std::istream& is = session.receiveResponse(res);
std::string str=std::string((std::istreambuf_iterator<char>(is)),
std::istreambuf_iterator<char>());
std::cout<<str;
} catch (Poco::Exception& e) {
result.set("error", 103);
result.set("errorMessage",e.what()+e.message());
result.set("success", "false");
}
std::ostringstream stream;
result.stringify(stream);
std::string str = stream.str();
std::cout<<""<<str<<"";
}
来源:https://stackoverflow.com/questions/29821524/error-using-statically-linked-poco-library-on-os-x-10-10-http-address-family-no