Linux 64 bit compilation errors

Mar 28, 2014 at 7:02 PM
Hi,

I keep getting the errors below when trying to use the library.
Here is the code in 'asteambuf.h' where the issue is:
#ifndef _MS_WINDOWS
// TFS 579628 - 1206: figure out how to avoid having this specialization for Linux (beware of 64-bit Linux)
namespace std {
    template<>
    struct char_traits<unsigned char> : private char_traits<char>
    {
    public:
        typedef unsigned char char_type;
.............................................................
The issues goes away if I just comment out the whole section.

Here are the compilation errors:
../../../Release/include/cpprest/astreambuf.h|65|error: specialization of ‘std::char_traits<unsigned char>’ after instantiation
../../../Release/include/cpprest/astreambuf.h|65|error: redefinition of ‘struct std::char_traits<unsigned char>’
/usr/include/c++/4.8/bits/char_traits.h|227|error: previous definition of ‘struct std::char_traits<unsigned char>’
here is the code to get this error:
void TestCasablanca()
{
  web::http::client::http_client client("http://www.microsoft.com");

  // Make the request and asynchronously process the response.
  client.request(methods::GET).then([](http_response response)
  {
      // Print the status code.
      cout << "Server returned returned status code " << response.status_code() << '.' << std::endl;

      // TODO: Perform actions here reading from the response stream.
      auto bodyStream = response.body();

      // In this example, we print the length of the response to the console.
      cout << "Content length is " << response.headers().content_length() << " bytes." << std::endl;
  }).wait();
} // TestCasablanca
GT
Coordinator
Apr 1, 2014 at 12:14 AM
Hi GT,

I'm trying to reproduce the issues you've outlined, but so far I've been unsuccessful. I expanded your code into the following:
#include "cpprest/http_client.h"
#include "cpprest/astreambuf.h"

#include <iostream>

using namespace std;

void TestCasablanca()
{
    web::http::client::http_client client("http://www.microsoft.com");

    // Make the request and asynchronously process the response.
    client.request(web::http::methods::GET).then(
        [](web::http::http_response response)
        {
            // Print the status code.
            cout << "Server returned returned status code " << response.status_code() << '.' << std::endl;

            // TODO: Perform actions here reading from the response stream.
            auto bodyStream = response.body();

            // In this example, we print the length of the response to the console.
            cout << "Content length is " << response.headers().content_length() << " bytes." << std::endl;
        }).wait();
}


int main()
{}
Further, I'm compiling with "-std=c++11".

But this code does not give me any of the errors you've listed. Could you extend your sample program with includes and a main function?

Thanks,
roschuma
Apr 1, 2014 at 3:44 AM
Here is the code which fails as described on Linux (Mint 16 x64):
#include <iostream>

typedef unsigned char bbyte;
typedef std::basic_string<bbyte> bytestring;

bytestring mystr;

#include "cpprest/http_client.h"
#include "cpprest/astreambuf.h"

using namespace std;

void TestCasablanca()
{
    web::http::client::http_client client("http://www.microsoft.com");

    // Make the request and asynchronously process the response.
    client.request(web::http::methods::GET).then(
        [](web::http::http_response response)
        {
            // Print the status code.
            cout << "Server returned returned status code " << response.status_code() << '.' << std::endl;

            // TODO: Perform actions here reading from the response stream.
            auto bodyStream = response.body();

            // In this example, we print the length of the response to the console.
            cout << "Content length is " << response.headers().content_length() << " bytes." << std::endl;
        }).wait();
}

int main()
{
  TestCasablanca();
    cout << "Hello world!" << endl;
    return 0;
}
///////////////////////////////////////////////////////////
So the issue is first the declaration:

typedef unsigned char bbyte;
typedef std::basic_string<bbyte> bytestring;

followed by creating a string like this:

bytestring mystr;

 ALL before including casablanca headers.

Note that if you create the string AFTER including casablanca headers, the code works!?

G.
Coordinator
Apr 1, 2014 at 3:45 PM
Hi G,

Fundamentally, this is an issue we're aware of (thus the TFS 579628 tracking identifier).

For now, the best workaround is to follow standard C++ practice and place all header includes at the top of the file before making any further declarations. If you continue to have issues, try placing the Casablanca includes before including the other standard library files.

roschuma