Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build nodejs as a shared library from source code

I need to include node.h in my c++ project, I tried to build node from source code using:

./configure
sudo make

I got a node executable and some object files and .a files, I need to build as .so file to use it in my c++ code.

I tried to build libnode, but I got cmakelists error and this is not official nodejs project.

if anybody know how to build nodejs from source code as .so file will be great, a similar question in a google group but the answer is not working.

like image 670
Ahmed Kato Avatar asked Dec 12 '22 15:12

Ahmed Kato


1 Answers

Support for building as a shared library has been added in to node mainline. Please see PR 6994 and specifically this comment.

I just ran

git clone https://github.com/nodejs/node.git
cd node
git checkout v6.9.4
./configure --shared
make -j4

which produced:

ubuntu@server:~/node$ find . -name libnode.so\* -exec ls -la {} \;
-rwxrwxr-x 2 ubuntu ubuntu 31576776 Jan  6 18:57 ./out/Release/lib.target/libnode.so.48
-rw-rw-r-- 1 ubuntu ubuntu 387 Jan  6 18:57 ./out/Release/.deps/home/ubuntu/node/out/Release/lib.target/libnode.so.48.d
-rw-rw-r-- 1 ubuntu ubuntu 4202 Jan  6 18:57 ./out/Release/.deps/home/ubuntu/node/out/Release/obj.target/libnode.so.48.d
-rwxrwxr-x 2 ubuntu ubuntu 31576776 Jan  6 18:57 ./out/Release/obj.target/libnode.so.48
ubuntu@server:~/node$ 
like image 107
Gardner Bickford Avatar answered Dec 21 '22 10:12

Gardner Bickford