5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Clang with Microsoft CodeGen(2016/07版)でWindows.hを使うときに注意すべきこと

Last updated at Posted at 2016-08-04

初めに

みなさん、Clang with Microsoft CodeGenは使ってますか?

まだの方は半年前に投稿した記事ですが

Clang with Microsoft CodeGenがでたので試す
http://qiita.com/yumetodo/items/bd41f31f39dd590e8c80

を見ましょう。地味にこまめに更新してます。

どんどん使える子になってきてるのでどんどん使ってあげましょう。コンパイルエラーわかりやすいですし。

かつて存在した問題

Clang with Microsoft CodeGen(July 2016)では、Windows.hをincludeすると

C:\Program Files (x86)\Windows Kits\8.1\Include\um\combaseapi.h(229,21): error : unknown type name 'IUnknown'
          static_cast<IUnknown*>(*pp);    // make sure everyone derives from IUnknown

とか怒られていました。

一体いつからかこれは修正されました(2016/12現在)

解決策

というわけでClang with Microsoft CodeGen(July 2016)でもコンパイルが通るように

#if defined(__c2__) &&  __clang_major__ == 3 && __clang_minor__ == 8
//To avoid compile error
//C:\Program Files (x86)\Windows Kits\8.1\Include\um\combaseapi.h(229,21): error : unknown type name 'IUnknown'
//          static_cast<IUnknown*>(*pp);    // make sure everyone derives from IUnknown
struct IUnknown;
#endif
#include <Windows.h>

としましょう。COM周りを使わなければClang with Microsoft CodeGen(July 2016)でもコンパイルが通るし、それ以外のバージョンにも被害は出ません。おまじない代わりにいかがですか?

5
4
4

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
5
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?