Node.js

[Node.js] Addons

melius102 2021. 3. 8. 06:03

https://nodejs.org/dist/latest-v14.x/docs/api/addons.html

https://github.com/nodejs/node

https://github.com/nodejs/node-addon-examples

1. Building

컴파일을 위해서 windows-build-tools와 node-gyp 패키지 설치가 필요하다.

 

1) windows-build-tools

https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md

https://www.npmjs.com/package/windows-build-tools

> npm install --global windows-build-tools
> npm config list

아래의 경로에 Python2와 Visual Studio Build Tools가 설치된다.

 

Python2 >> C:\Users\[user]\.windows-build-tools\python27\python.exe

MSBuild >> C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe

 

* cl.exe도 설치되며, 'Developer Command Prompt for VS 2017'을 실행하면 C++ 코드를 컴파일할 수 있다.

> cl /EHsc hello.cc /Fe: hello.exe
// '/Fe' Renames the executable file.
// '/EH' Exception handling model

 

 

2) node-gyp (option 1)

https://github.com/nodejs/node-gyp#installation

> npm install -g node-gyp

프로젝트 루트에서 아래의 명령 실행

> node-gyp configure  // once
> node-gyp build

 

 

3) cmake.js (option 2)

https://www.npmjs.com/package/cmake-js

 

 

4) etc.

https://github.com/workshopper/goingnative

https://www.youtube.com/watch?v=4OQNsg6xLdk

> where node
> npm root -g
> npm i goingnative