Important: Please read the Qt Code of Conduct -

Unable to build qtdeclarative (cross-compiling Qt5 for Raspberry Pi zero W): Error ‘PATH_MAX’ was not declared in this scope

  • I have successfully cross-compiled qtbase for Raspberry Pi 0 W (by following , but I'm unable to build the sub-module QtDeclarative for adding QML support. With Qt5.15.0 I'm getting the following error :

    /qtdeclarative/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp:86:14: error: ‘PATH_MAX’ was not declared in this scope
         char buf[PATH_MAX];

    What am I doing wrong ?

  • Moderators

    @glamis I'm not sure why PATH_MAX isn't found in your source code, but this post should help you understand what it is:

  • I ran into the same problem using GCC 8.3 as a cross compiler with the latest (as of 3-10-2020) raspbian. I guess that previously PATH_MAX was leaked by another header, hiding this bug. I fixed it by simply replacing the macro PATH_MAX with a constant (1024). That should be plenty of space to hold the 20 or so bytes that are copied into buf, which isn't a real path anyway.

    diff --git a/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp b/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp
    index d59fdcd675..56cd753bb5 100644
    --- a/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp
    +++ b/src/3rdparty/masm/wtf/OSAllocatorPosix.cpp
    @@ -74,7 +74,7 @@ static int memfdForUsage(size_t bytes, OSAllocator::Usage usage)
    -    char buf[PATH_MAX];
    +    char buf[1024 /* PATH_MAX */];
         strcpy(buf, type);
         strcat(buf, "QtQml");

    The actual fix is to either include linux/limits.h or fix memfdForUsage() to not allocate such a huge stack buffer for no reason at all.

Log in to reply