LoginSignup
3
2

# コンパイル
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
ver. 0.12 ありがとう追記 20230312

最後までおよみいただきありがとうございました。

いいね 💚、フォローをお願いします。

Thank you very much for reading to the last sentence.

Please press the like icon 💚 and follow me for your happy life.

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2