Error when compile SlateViewer

Hi I try to compile UE4.9 but when i try to compile SlateViewer I get this error

In file included from /home/piero/UnrealEngine/Engine/Intermediate/Build/Linux/x86_64-unknown-linux-gnu/SlateViewer/Development/ImageWrapper/Module.ImageWrapper.cpp:9:
In file included from /home/piero/UnrealEngine/Engine/Source/Developer/ImageWrapper/Private/JpegImageWrapper.cpp:14:
ThirdParty/libJPG/jpgd.cpp:569:51: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
        static const int s_extend_offset[16] = { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7...
                                                     ~~~~^
ThirdParty/libJPG/jpgd.cpp:569:66: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
        static const int s_extend_offset[16] = { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7...
                                                                    ~~~~^
ThirdParty/libJPG/jpgd.cpp:569:81: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
        static const int s_extend_offset[16] = { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7...
                                                                                   ~~~~^
ThirdParty/libJPG/jpgd.cpp:569:96: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
        static const int s_extend_offset[16] = { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7...
                                                                                                  ~~~~^
ThirdParty/libJPG/jpgd.cpp:569:111: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
        static const int s_extend_offset[16] = { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7...
                                                                                                                 ~~~~^
ThirdParty/libJPG/jpgd.cpp:569:126: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
  ...const int s_extend_offset[16] = { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8...
                                                                                                                      ~~~~^
ThirdParty/libJPG/jpgd.cpp:569:141: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
  ...= { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, ((-1)<<9) + 1, ((-1)<<1...
                                                                                                       ~~~~^
ThirdParty/libJPG/jpgd.cpp:569:156: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
  ...= { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, ((-1)<<9) + 1, ((-1)<<1...
                                                                                                                      ~~~~^
ThirdParty/libJPG/jpgd.cpp:569:171: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
  ...+ 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1, ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11...
                                                                                                                    ~~~~^
ThirdParty/libJPG/jpgd.cpp:569:186: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
  ...+ 1, ((-1)<<3) + 1, ((-1)<<4) + 1, ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<1...
                                                                                                                    ~~~~^
ThirdParty/libJPG/jpgd.cpp:569:202: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
  ...+ 1, ((-1)<<4) + 1, ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1, ((-1)<<...
                                                                                                                     ~~~~^
ThirdParty/libJPG/jpgd.cpp:569:218: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
  ...+ 1, ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1, ((-1)<<13) + 1, ((-1)<...
                                                                                                                      ~~~~^
ThirdParty/libJPG/jpgd.cpp:569:234: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
  ...+ 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1, ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1, ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)...
                                                                                                                       ~~~~^
ThirdParty/libJPG/jpgd.cpp:569:250: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
  ...+ 1, ((-1)<<7) + 1, ((-1)<<8) + 1, ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1, ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
                                                                                                                        ~~~~^
ThirdParty/libJPG/jpgd.cpp:569:266: error: shifting a negative signed value is undefined [-Werror,-Wshift-negative-value]
  ...+ 1, ((-1)<<7) + 1, ((-1)<<8) + 1, ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1, ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
                                                                                                                                        ~~~~^
15 errors generated.

And the compiler will fail. I’m using fedora and clang 3.7

Hey Piko-

4.9 can only be compiled with clang 3.6 and clang 3.5, trying other versions may result in compilation errors. For now I would suggest switching to another version of Clang.

Cheers

Thanks now the compilation work

Another workaround you could use is the following:

  • Open the file “./Engine/Source/Programs/UnrealBuildTool/Linux/LinuxToolChain.cs”

  • Insert the following piece of code after line 343

    if (CompilerVersionGreaterOrEqual(3, 7, 0))
    {
    Result += " -Wno-shift-negative-value"; // Triggered by ThirdParty/libJPG due to usage of: (-1) << …
    }

  • Rerun GenerateProjectFiles.sh

  • Rebuild Engine

I seriously dislike the use of flags such as these though… Imho it just promotes bad coding and should never be used/needed…
If this wasn’t a third-party library issue I’d be fixing the engine code right now instead of supplying this workaround…

It could potentially actually be fixed instead of worked around by changing those (-1)'s to (std::numeric_limits::max()), (UINT_MAX) or ((unsigned)-1), unless they’re trying to achieve something completely different here, but then we would be messing with an external library…

@-; Maybe in the future it’d be nice to have the UnrealBuildTool handle compiler flags on a per project or per group basis (for example, flags for Third-Party projects only and flags for UE4 only).
That way we could ensure good and clean code in the engine itself by gradually removing all such flags for the engine while still being able to work around bad code in third-party libraries.

But, this maybe mean that it’s necessery install a third party for avoid this errors?
Will be useful that put this requeriments in the docs.

ANd yes, i don’t know if this issue was solved installing libjpeg or put these code in the file, but, i fixed it.

You don’t install anything extra here; we’re compiling source.
The piece of source code that causes the problem is located in a third-party library that is included in the UE4 source tree (…/ThirdParty/libJPG/*). For this reason I supplied the UnrealBuildTool option as a possible solution but the proper fix to this error would be for the upstream third-party library to fix this piece of code.

line 343 for me reads:

 if (CompileEnvironment.Config.Target.Configuration == CPPTargetConfiguration.Shipping)

after that is:

        {
            Result += " -Wno-unused-value";

            // in shipping, strip as much info as possible
            Result += " -g0";
            Result += " -fomit-frame-pointer";
            Result += " -fvisibility=hidden";           // prevents from exporting all symbols (reduces the size of the binary)
        }
        else if (CompileEnvironment.Config.Target.Configuration == CPPTargetConfiguration.Debug)
        {
            Result += " -fno-inline";                   // disable inlining for better debuggability (e.g. callstacks, "skip file" in gdb)
        }

are you sure line 343 is correct?

./Setup.sh doesn’t work with clang 3.6 for me. It only works with the latest version of clang for me, but of course make fails with the latest version of clang for me because of clang errors or something, and it’s recommended to downgrade clang to get around those errors!!!

If you’re building UE4.9, then yes I’m sure that number is correct.
However, you’re replying to a post that is more than a year old. Assuming you’ve been updating the engine since 4.9 was released, the chance this number is still valid is very small.

Furthermore, as far as I’m aware this has since been fixed in ‘ThirdParty/libJPG/jpgd.cpp’ so you should not be needing this at all.

The latest release atm should support clang 3.5 up to and including 3.9 just fine.
This question is a year old. Could you please specify if you are still using 4.9?