OpenShadingLanguage: Build issues on macOS Catalina (fatal error: 'wchar.h' file not found)

Problem

Expected behavior:

Actual behavior: CMake works good without warnings, but i couldn’t build it.

스크린샷 2019-09-05 오후 1 34 50

I guess this issue is related to this

Versions

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

Solution for macOS Catalina 10.15.3

Use Mac Ports for installing LLVM version 9.0 (sudo port install llvm-9.0). We’re going to use the clang and clang++ compiler that’s included in this package for compiling OSL. Therefore, the command to build OSL from inside its directory will be (we nuke any existing build first):

make nuke &&  make LLVM_VERSION=9.0 LLVM_DIRECTORY=/opt/local/libexec/llvm-9.0 \
MYCC=/opt/local/libexec/llvm-9.0/bin/clang MYCXX=/opt/local/libexec/llvm-9.0/bin/clang++  -j16

Take a good look at your llvm-9.0 directory if you installed it differently and adjust the paths. Also, I specified -j16 to use 16 parallel threads for building. If you don’t have a strong machine, change this or leave it out entirely.

Attention: If you only use this, then it will end in the error message as described in the issue. The problem is that wchar.h that comes with llvm is only a stub that contains the line

#include_next <wchar.h>

That means that it expects the real wchar.h to be accessible which it is not. The correct wchar.h is provided by the command line tools that you need to install. Since this is also a prerequisite to use Mac Ports, you probably already have done this. If not, check the first part of the installation instructions for Mac Ports which explains the two simple steps.

If you have the command line tools, then the folder /Library/Developer/CommandLineTools should exist on your machine. In this directory, the different SDKs are available and we’ll use this include path in addition to the include path that LLVM already uses. Therefore, we set the following environment variable for clang++ before building OSL

export CPLUS_INCLUDE_PATH=/opt/local/libexec/llvm-9.0/include/c++/v1:/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include

It is vitally important that you also include LLVM’s normal include path because it should first look there! After that, OSL should build fine.

That’s actually a problem with your Mac. I’ve had the same trouble myself after certain xcode updates. You need to follow these directions:

https://stackoverflow.com/questions/52509602/cant-compile-c-program-on-a-mac-after-upgrade-to-mojave/52530212#52530212

Basically, the solution that worked for me boils down to:

xcode-select --install
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

Updating: I ran into this problem on a machine with Catalina, and as said earlier in this thread, the original trick of running macOS_SDK_headers_for_macOS_10.14.pkg that I mentioned above no longer works because 10.15 doesn’t include this pkg.

The diagnosis of the problem and the advice from @halirutan is correct but assumes paths for Macports, so just for the record, for anybody using Homebrew, the simple solution is just to set:

CPLUS_INCLUDE_PATH=/usr/local/opt/llvm/include/c++/v1:/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include

@lgritz I had looked into the SO post you mentioned and tried various things. It’s just not clear to me what happens, but here is a more elaborate report: I looked up the tool-chain with

$ xcode-select -p
/Applications/Xcode.app/Contents/Developer

That indicates to me that headers and libraries should come from the Xcode toolchains available. So I checked for wchar.h

% find . -name "wchar.h"
./Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/usr/include/wchar.h
./Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/wchar.h
./Platforms/WatchOS.platform/Developer/SDKs/WatchOS.sdk/usr/include/wchar.h
./Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/wchar.h
./Platforms/MacOSX.platform/Developer/SDKs/DriverKit19.0.sdk/System/DriverKit/usr/include/wchar.h
./Platforms/WatchSimulator.platform/Developer/SDKs/WatchSimulator.sdk/usr/include/wchar.h
./Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator.sdk/usr/include/wchar.h
./Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/include/wchar.h
./Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/wchar.h

The viable options seem to be the XcodeDefault.xctoolchain and the MacOSX.platform/Developer/SDKs/MacOSX.sdk but I don’t have any in-depth knowledge of how they are different. Using the latter option and setting

$ export CPATH=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
$ make nuke &&  make LLVM_VERSION=9.0 LLVM_DIRECTORY=/opt/local/libexec/llvm-9.0 VERBOSE=1

gives a whole lot of other errors.

Log File
[  2%] Generating llvm_ops.bc.cpp
cd /Users/pscheibe/workspace/OpenShadingLanguage/src/liboslexec && /opt/local/libexec/llvm-9.0/bin/clang++ -DOSL_FAST_MATH=1 -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -DUSE_STD_REGEX -DOSL_LLVM_VERSION=90 -DOSL_LLVM_FULL_VERSION="9.0.1" -std=c++11 -I/Users/pscheibe/workspace/OpenShadingLanguage/src/liboslexec -I/Users/pscheibe/workspace/OpenShadingLanguage/src/include -I/Users/pscheibe/workspace/OpenShadingLanguage/build/macosx/include -I/opt/local/include -I/opt/local/include -isystem\ /opt/local/include -DOSL_COMPILING_TO_BITCODE=1 -Wno-deprecated-register -O3 -fno-math-errno -S -emit-llvm -o /Users/pscheibe/workspace/OpenShadingLanguage/build/macosx/src/liboslexec/llvm_ops.s llvm_ops.cpp
In file included from llvm_ops.cpp:104:
In file included from /Users/pscheibe/workspace/OpenShadingLanguage/src/include/OSL/oslconfig.h:66:
In file included from /opt/local/include/OpenImageIO/errorhandler.h:10:
In file included from /opt/local/include/OpenImageIO/strutil.h:23:
In file included from /opt/local/include/OpenImageIO/hash.h:19:
In file included from /opt/local/libexec/llvm-9.0/bin/../include/c++/v1/unordered_map:409:
In file included from /opt/local/libexec/llvm-9.0/bin/../include/c++/v1/__hash_table:18:
/opt/local/libexec/llvm-9.0/bin/../include/c++/v1/cmath:313:9: error: no member named 'signbit' in the global namespace
using ::signbit;
    ~~^
/opt/local/libexec/llvm-9.0/bin/../include/c++/v1/cmath:314:9: error: no member named 'fpclassify' in the global namespace
using ::fpclassify;
    ~~^
/opt/local/libexec/llvm-9.0/bin/../include/c++/v1/cmath:315:9: error: no member named 'isfinite' in the global namespace; did you mean 'finite'?
using ::isfinite;
    ~~^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/math.h:749:12: note: 'finite' declared here
extern int finite(double)
         ^
In file included from llvm_ops.cpp:104:
In file included from /Users/pscheibe/workspace/OpenShadingLanguage/src/include/OSL/oslconfig.h:66:
In file included from /opt/local/include/OpenImageIO/errorhandler.h:10:
In file included from /opt/local/include/OpenImageIO/strutil.h:23:
In file included from /opt/local/include/OpenImageIO/hash.h:19:
In file included from /opt/local/libexec/llvm-9.0/bin/../include/c++/v1/unordered_map:409:
In file included from /opt/local/libexec/llvm-9.0/bin/../include/c++/v1/__hash_table:18:
/opt/local/libexec/llvm-9.0/bin/../include/c++/v1/cmath:316:9: error: no member named 'isinf' in the global namespace
using ::isinf;
    ~~^
/opt/local/libexec/llvm-9.0/bin/../include/c++/v1/cmath:317:9: error: no member named 'isnan' in the global namespace
using ::isnan;
    ~~^
/opt/local/libexec/llvm-9.0/bin/../include/c++/v1/cmath:318:9: error: no member named 'isnormal' in the global namespace
using ::isnormal;
    ~~^
/opt/local/libexec/llvm-9.0/bin/../include/c++/v1/cmath:319:7: error: no member named 'isgreater' in the global namespace; did you mean '::std::greater'?
using ::isgreater;
    ^~
/opt/local/libexec/llvm-9.0/bin/../include/c++/v1/functional:731:29: note: '::std::greater' declared here
struct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool>
                          ^
In file included from llvm_ops.cpp:104:
In file included from /Users/pscheibe/workspace/OpenShadingLanguage/src/include/OSL/oslconfig.h:66:
In file included from /opt/local/include/OpenImageIO/errorhandler.h:10:
In file included from /opt/local/include/OpenImageIO/strutil.h:23:
In file included from /opt/local/include/OpenImageIO/hash.h:19:
In file included from /opt/local/libexec/llvm-9.0/bin/../include/c++/v1/unordered_map:409:
In file included from /opt/local/libexec/llvm-9.0/bin/../include/c++/v1/__hash_table:18:
/opt/local/libexec/llvm-9.0/bin/../include/c++/v1/cmath:320:7: error: no member named 'isgreaterequal' in the global namespace; did you mean '::std::greater_equal'?
using ::isgreaterequal;
    ^~
/opt/local/libexec/llvm-9.0/bin/../include/c++/v1/functional:760:29: note: '::std::greater_equal' declared here
struct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool>
                          ^
In file included from llvm_ops.cpp:104:
In file included from /Users/pscheibe/workspace/OpenShadingLanguage/src/include/OSL/oslconfig.h:66:
In file included from /opt/local/include/OpenImageIO/errorhandler.h:10:
In file included from /opt/local/include/OpenImageIO/strutil.h:23:
In file included from /opt/local/include/OpenImageIO/hash.h:19:
In file included from /opt/local/libexec/llvm-9.0/bin/../include/c++/v1/unordered_map:409:
In file included from /opt/local/libexec/llvm-9.0/bin/../include/c++/v1/__hash_table:18:
/opt/local/libexec/llvm-9.0/bin/../include/c++/v1/cmath:321:9: error: no member named 'isless' in the global namespace
using ::isless;
    ~~^
/opt/local/libexec/llvm-9.0/bin/../include/c++/v1/cmath:322:9: error: no member named 'islessequal' in the global namespace
using ::islessequal;
    ~~^
/opt/local/libexec/llvm-9.0/bin/../include/c++/v1/cmath:323:9: error: no member named 'islessgreater' in the global namespace
using ::islessgreater;
    ~~^
/opt/local/libexec/llvm-9.0/bin/../include/c++/v1/cmath:324:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
    ~~^
/opt/local/libexec/llvm-9.0/bin/../include/c++/v1/cmath:325:9: error: no member named 'isunordered' in the global namespace
using ::isunordered;
    ~~^
In file included from llvm_ops.cpp:104:
In file included from /Users/pscheibe/workspace/OpenShadingLanguage/src/include/OSL/oslconfig.h:66:
In file included from /opt/local/include/OpenImageIO/errorhandler.h:10:
In file included from /opt/local/include/OpenImageIO/strutil.h:23:
In file included from /opt/local/include/OpenImageIO/hash.h:25:
/opt/local/include/OpenImageIO/fmath.h:58:12: error: no member named 'isfinite' in namespace 'std'; did you mean 'finite'?
using std::isfinite;
    ~~~~~^~~~~~~~
         finite
/opt/local/libexec/llvm-9.0/bin/../include/c++/v1/cmath:315:9: note: 'finite' declared here
using ::isfinite;
      ^
In file included from llvm_ops.cpp:104:
In file included from /Users/pscheibe/workspace/OpenShadingLanguage/src/include/OSL/oslconfig.h:66:
In file included from /opt/local/include/OpenImageIO/errorhandler.h:10:
In file included from /opt/local/include/OpenImageIO/strutil.h:23:
In file included from /opt/local/include/OpenImageIO/hash.h:25:
/opt/local/include/OpenImageIO/fmath.h:59:12: error: no member named 'isinf' in namespace 'std'
using std::isinf;
    ~~~~~^
/opt/local/include/OpenImageIO/fmath.h:60:12: error: no member named 'isnan' in namespace 'std'
using std::isnan;
    ~~~~~^
In file included from llvm_ops.cpp:104:
In file included from /Users/pscheibe/workspace/OpenShadingLanguage/src/include/OSL/oslconfig.h:66:
In file included from /opt/local/include/OpenImageIO/errorhandler.h:10:
In file included from /opt/local/include/OpenImageIO/strutil.h:46:
In file included from /opt/local/include/OpenImageIO/fmt/ostream.h:12:
/opt/local/include/OpenImageIO/fmt/format.h:1729:14: error: expected unqualified-id
  if (std::signbit(value)) {  // value < 0 is false for NaN so use signbit.
           ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/math.h:170:5: note: expanded from macro 'signbit'
  ( sizeof(x) == sizeof(float)  ? __inline_signbitf((float)(x))        \
  ^
In file included from llvm_ops.cpp:104:
In file included from /Users/pscheibe/workspace/OpenShadingLanguage/src/include/OSL/oslconfig.h:66:
In file included from /opt/local/include/OpenImageIO/errorhandler.h:10:
In file included from /opt/local/include/OpenImageIO/strutil.h:46:
In file included from /opt/local/include/OpenImageIO/fmt/ostream.h:12:
/opt/local/include/OpenImageIO/fmt/format.h:1736:15: error: expected unqualified-id
  if (!std::isfinite(value)) {
            ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/math.h:155:5: note: expanded from macro 'isfinite'
  ( sizeof(x) == sizeof(float)  ? __inline_isfinitef((float)(x))       \
  ^
In file included from llvm_ops.cpp:104:
In file included from /Users/pscheibe/workspace/OpenShadingLanguage/src/include/OSL/oslconfig.h:66:
In file included from /opt/local/include/OpenImageIO/errorhandler.h:10:
In file included from /opt/local/include/OpenImageIO/strutil.h:46:
In file included from /opt/local/include/OpenImageIO/fmt/ostream.h:12:
/opt/local/include/OpenImageIO/fmt/format.h:1737:23: error: expected unqualified-id
    auto str = std::isinf(value) ? (fspecs.upper ? "INF" : "inf")
                    ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/math.h:160:5: note: expanded from macro 'isinf'
  ( sizeof(x) == sizeof(float)  ? __inline_isinff((float)(x))          \
  ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

Using other settings gives other errors. I realize that this is not a problem of OSL because it’s LLVM being incompatible with compiler settings. But information is scarce and every supposed-to-be-solution that’s on the web just feels like people are fumbling around until they get it working. I couldn’t find a reasonable explanation of what really happens, but if someone has further ideas, I’m happy to try them out.