Windowsでnode-gypのビルドを通す - その2
Windowsでnode-gypのビルドを通す - なにか作るの続き。
前回いろいろやったけれど、やっぱり一部のパッケージのビルドが通らなかった。こんなエラーが出てしまう。
fatal error C1083: Cannot open include file: 'nan.h': No such file or directory
よくわからないけれど、個々のパッケージじゃなくて node-gyp の問題らしい。Cannot include nan.h · Issue #56 · adobe-research/theseus · GitHubを参考にすると include ディレクトリーに nan.h を入れるのが一時的な解決法だとか。この nan.h は npm install nan -g
でインストールしたディレクトリー内にある。
Visual Studio 2010 C++ の “VC++ ディレクトリ” 設定はどこへ? | re-Think thingsを参考に include ディレクトリーの設定を行う。
Microsoft.Cpp.x64.user.props を以下のように変更する(x86 なら Microsoft.Cpp.Win32.user.props の方を変更するのかな?)。
<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ImportGroup Label="PropertySheets"> </ImportGroup> <PropertyGroup Label="UserMacros" /> <PropertyGroup> <ExecutablePath>$(ExecutablePath)</ExecutablePath> <IncludePath>C:\lib\cpp;${IncludePath)</IncludePath> <ReferencePath>$(ReferencePath)</ReferencePath> <LibraryPAth>$(LibraryPAth)</LibraryPAth> <SourcePath>$(SourcePath)</SourcePath> <ExcludePath>$(ExcludePath)</ExcludePath> </PropertyGroup> <ItemDefinitionGroup /> <ItemGroup /> </Project>
nan.h は C:\lib\cpp の中にコピーする。
これで行けるだろう、と思ったらまだエラーが出る。
fatal error C1083: Cannot open include file: 'stddef.h': No such file or directory
この stddef.h は VisualStudio 2013 と同時に導入されるようなのだが、なぜかビルド時に参照されていない。正しいのかわからないが、stddef.h の含まれるディレクトリーも IncludePath に含めてしまう。
<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ImportGroup Label="PropertySheets"> </ImportGroup> <PropertyGroup Label="UserMacros" /> <PropertyGroup> <ExecutablePath>$(ExecutablePath)</ExecutablePath> <IncludePath>C:\lib\cpp;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\crt\src;${IncludePath)</IncludePath> <ReferencePath>$(ReferencePath)</ReferencePath> <LibraryPAth>$(LibraryPAth)</LibraryPAth> <SourcePath>$(SourcePath)</SourcePath> <ExcludePath>$(ExcludePath)</ExcludePath> </PropertyGroup> <ItemDefinitionGroup /> <ItemGroup /> </Project>
まだエラーが出る。
fatal error C1083: Cannot open include file: 'sal.h': No such file or directory
これは Windows SDK とやらの中に含まれているらしい。VisualStudio 2013 なら既にインストールされているようだ。やけくそで IncludePath を追加する。
<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ImportGroup Label="PropertySheets"> </ImportGroup> <PropertyGroup Label="UserMacros" /> <PropertyGroup> <ExecutablePath>$(ExecutablePath)</ExecutablePath> <IncludePath>C:\lib\cpp;C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\crt\src;C:\Program Files (x86)\Windows Kits\8.1\Include\Shared;C:\Program Files (x86)\Windows Kits\8.1\Include\um;${IncludePath)</IncludePath> <ReferencePath>$(ReferencePath)</ReferencePath> <LibraryPAth>$(LibraryPAth)</LibraryPAth> <SourcePath>$(SourcePath)</SourcePath> <ExcludePath>$(ExcludePath)</ExcludePath> </PropertyGroup> <ItemDefinitionGroup /> <ItemGroup /> </Project>
これで何とか上手くビルドが通るようになった!
ちなみに、C++ 全然わかりません。紹介した方法はあまり正しい方法っぽくもないので、マネをする方は自己責任で!