Sysroot is incorrect in Ninja when trying to build library

Viewed 798

I'm trying to build Google's Skia library on Mac, but when I try running

ninja -C out/Static/

in order to build the library, it gives me this error (after many, many similar errors):

[14/1073] compile ../../src/gpu/GrBackendTextureImageGenerator.cpp
FAILED: obj/src/gpu/gpu.GrBackendTextureImageGenerator.o 
c++ -MD -MF obj/src/gpu/gpu.GrBackendTextureImageGenerator.o.d -DNDEBUG -DSK_ASSUME_GL=1 -DSK_ENABLE_API_AVAILABLE -DSK_GAMMA_APPLY_TO_A8 -DSKIA_IMPLEMENTATION=1 -DSK_GL -I../.. -Wno-attributes -fstrict-aliasing -fPIC -fvisibility=hidden -isysroot b\'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk\\n\' -O3 -Wno-sign-conversion -Wno-unused-parameter -std=c++17 -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -c ../../src/gpu/GrBackendTextureImageGenerator.cpp -o obj/src/gpu/gpu.GrBackendTextureImageGenerator.o
clang: warning: no such sysroot directory: 'b'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk\n'' [-Wmissing-sysroot]
In file included from ../../src/gpu/GrBackendTextureImageGenerator.cpp:8:
In file included from ../../include/gpu/GrContext.h:11:
In file included from ../../include/core/SkMatrix.h:11:
In file included from ../../include/core/SkRect.h:11:
In file included from ../../include/core/SkPoint.h:11:
In file included from ../../include/core/SkMath.h:11:
../../include/core/SkTypes.h:26:18: fatal error: 'TargetConditionals.h' file not found
        #include "TargetConditionals.h"
                 ^~~~~~~~~~~~~~~~~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.

It seems like the sysroot directory b'/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk\n' is wrong, however "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk" does exist and "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/" has the file TargetConditionals.h.

I haven't used ninja before, but I tried looking in toolchain.ninja but could find no way to change the sysroot variable. I also reinstalled Xcode and Xcode command line tools, to no avail. Any help would be greatly appreciated!

1 Answers

I too struggled a lot. The solutions that I tried:

  1. xcode-select --install for installing command line tools. But it used to say that command line tools are already installed.
  2. Tried re-installing xcode to fix some linkage issue.
  3. Tried a could of other solutions found on web.

Finally, what worked for me is by switching to python2. I had python2 and python3 installed. My path environment variable in .zshrc was giving precedence to python3. So, all internal scripts generated by ninja had python3 in precedence.

I temporarily removed python3, you can keep both but its precedence should be changed. Then regenerate build directory using gn. Then use ninja to build.

Note: clang: warning: no such sysroot directory: 'b'/Applications/ : Here 'b' use to represent that string literal should be treated as byte literal in python3. So that could be the cause.

Related