Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
1
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

'wchar.h' file not found で困った clang++ macOS

コンパイル

clang++で標記エラーで作業が丸2日進まなかった。

コンパイルスクリプト

コンパイル用shell script C版(clangとgcc)とC++版(clang++とg++)
https://qiita.com/kaizen_nagoya/items/74220c0577a512c2d7da
で定義したスクリプトを使う。

#!/bin/sh
echo "clang++ $1.cpp"
clang++ $1.cpp -o $1l
./$1l $2
echo "g++-7 $1.cpp"
g++-7 $1.cpp -o $1g
./$1g $2

ソースコード

CERT CPP入門(1) Rule 01. Declarations and Initialization (DCL)
https://qiita.com/kaizen_nagoya/items/61b3c431756fe8e6af3e

dcl50n2.cpp
//clang version 6.0.0 (tags/RELEASE_600/final)
//g++-7 (Homebrew GCC 7.3.0_1) 7.3.0
#include <iostream>
#include <cstdarg>

int add(int first, int second, ...) {
  int r = first + second; 
  va_list va;
  va_start(va, second);
  while (int v = va_arg(va, int)) {
    r += v;
  }
  va_end(va);
  return r;
}  

int main(int argc, char**argv) {
  int i=1;
  i=add(argc, i);
  std::cout << i << std::endl;
  return argc;
}

エラー

$ ./certcpp.sh dl50n2
clang++ dl50n2.cpp
In file included from dl50n2.cpp:1:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/iostream:38:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/ios:215:
In file included from /usr/local/Cellar/llvm/6.0.0/include/c++/v1/iosfwd:90:
/usr/local/Cellar/llvm/6.0.0/include/c++/v1/wchar.h:119:15: fatal error: 'wchar.h' file not found
#include_next <wchar.h>
              ^~~~~~~~~
1 error generated.
./certcpp.sh: line 4: ./dl50n2l: No such file or directory
g++-7 dl50n2.cpp
-460557205

検索

「fatal error: 'wchar.h' file not found」検索

'wchar.h' file not found
https://stackoverflow.com/questions/46342411/wchar-h-file-not-found

解1

 I was able to fix it using symbolic link. This is what I made :
$ cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
$sudo ln -s MacOSX.sdk MacOSX10.07.sdk

今、10.13

$sudo ln -s MacOSX.sdk MacOSX10.13.sdk

解2 同じく上記URLから

The solution was to run CMake, 'Delete Cache', and 'Configure' the project again. 
$ brew install cmake

解3

clang++ via homebrew (llvm38) - compile error with system includes
https://stackoverflow.com/questions/37321840/clang-via-homebrew-llvm38-compile-error-with-system-includes

$ x-code-select --install

結果

$ ./certcpp.sh dl50n2
clang++ dl50n2.cpp
-698595334
g++-7 dl50n2.cpp
-292400021

やっと解決。何が効いたか。多分解3。

stack overvlow恐るべし。感謝。

参考文献

Qiitaに投稿するC, C++のStyle例(暫定)
https://qiita.com/kaizen_nagoya/items/946df1528a6a1ef2bc0d

文書履歴

ver 0.10 初稿 20180324
ver 0.11 追記 20180408

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
1
Help us understand the problem. What are the problem?