3

While using the libraries of c++rest and python together in my c++ code, I get an error of function "tolower" to be undefined. I get to understand because in python pyport.h there is a

#undef tolower
#define tolower(c) towlower(btowc(c))

But at the same time c++rest/asyncrt_utils.cpp there is a private method called tolower in the cmp class.

class cmp
{

public:

    static int icmp(std::string left, std::string right)
    {
        size_t i;
        for (i = 0; i < left.size(); ++i)
        {
            if (i == right.size()) return 1;

            auto l = cmp::tolower(left[i]);
            auto r = cmp::tolower(right[i]);
            if (l > r) return 1;
            if (l < r) return -1;
        }
        if (i < right.size()) return -1;
        return 0;
    }

private:
    static char tolower(char c)
    {
        if (c >= 'A' && c <= 'Z')
            return static_cast<char>(c - 'A' + 'a');
        return c;
    }
};

What could be the solution for this? how do I make sure the compilation happens preserving both

P.S. I have tried checking the order in which these .h files get called in my code. c++rest is always called at the end of the list.

Any suggestions would be appreciated. Want to have a discussion on similar things. I would like to learn more about the compilers and how they work

pavan kota
  • 41
  • 2
  • 2
    There's only one true solution: fix [pyport.h upstream](https://svn.python.org/projects/python/trunk/Include/pyport.h). Not joking. – YSC Jan 25 '19 at 15:52
  • Notice: [`tolower` is not a reserved name of POSIX](http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html). Is it a C++ reserved name? I think not. Can someone confirm? – YSC Jan 25 '19 at 15:59
  • how do I fix pyport.h?? Could you please elaborate? – pavan kota Jan 27 '19 at 09:41

0 Answers0