Does anyone see something wrong with my binding file?
Yes:
"libraries": [ "-lgstreamer-1.0", "-L/usr/include/gstreamer-1.0/gst/" ],
The "libraries" element in binding.gyp must contain the libraries specified in -l or the absolute form of the file name you want to link.
-lgstreamer-1.0 is one such. -L/usr/inlcude/gstreamer-1.0/gst/ not. This is a linker option that will instruct the linker to search for libraries specified in the -l form in the /usr/include/gstreamer-1.0/gst/ directory.
This indicates the search directory in the library, so if necessary, you should say this in the "library_dirs" element:
"library_dirs": [ "/usr/inlcude/gstreamer-1.0/gst/", ]
But you do not need this, because there /usr/inlcude/gstreamer-1.0/gst/ no libraries in /usr/inlcude/gstreamer-1.0/gst/ . All files under /usr/include are C or C ++ header files, not libraries. Libraries are installed in /lib , /usr/lib or /usr/local/lib .
You say you can successfully compile the program with:
g++ main.c -o main `pkg-config --cflags --libs gstreamer-1.0`
This works because, as you know,
pkg-config --cflags --libs gstreamer-1.0
displays the compiler and linker options needed to create a target that depends on gstreamer-1.0
We'll see:
$ pkg-config --cflags --libs gstreamer-1.0 -pthread -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 \ -I/usr/lib/x86_64-linux-gnu/glib-2.0/include \ -lgstreamer-1.0 -lgobject-2.0 -lglib-2.0
Then use this information to write binding.gyp . (On your system, this may be different from mine):
binding.gyp
{ "targets": [ { "target_name": "addon", "include_dirs": [ "/usr/include/gstreamer-1.0", "/usr/include/glib-2.0", "/usr/lib/x86_64-linux-gnu/glib-2.0/include" ], "libraries": [ "-lgstreamer-1.0", "-lgobject-2.0", "-lglib-2.0" ], "sources": [ "hello.cc" ] } ] }
(Have we forgotten that the -pthread option -pthread selected by pkg-config ? No. node-gyp goes through this default compiler and linker)
With this binding.gyp your build should look something like mine:
$ node-gyp configure build gyp info it worked if it ends with ok gyp info using node-gyp@3.4.0 gyp info using node@4.7.2 | linux | x64 gyp info spawn /usr/bin/python2 gyp info spawn args [ '/usr/share/node-gyp/gyp/gyp_main.py', gyp info spawn args 'binding.gyp', gyp info spawn args '-f', gyp info spawn args 'make', gyp info spawn args '-I', gyp info spawn args '/home/imk/develop/so/scrap/build/config.gypi', gyp info spawn args '-I', gyp info spawn args '/usr/share/node-gyp/addon.gypi', gyp info spawn args '-I', gyp info spawn args '/usr/include/nodejs/common.gypi', gyp info spawn args '-Dlibrary=shared_library', gyp info spawn args '-Dvisibility=default', gyp info spawn args '-Dnode_root_dir=/usr/include/nodejs', gyp info spawn args '-Dnode_gyp_dir=/usr/share/node-gyp', gyp info spawn args '-Dnode_lib_file=node.lib', gyp info spawn args '-Dmodule_root_dir=/home/imk/develop/so/scrap', gyp info spawn args '--depth=.', gyp info spawn args '--no-parallel', gyp info spawn args '--generator-output', gyp info spawn args 'build', gyp info spawn args '-Goutput_dir=.' ] gyp info spawn make gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ] make: Entering directory '/home/imk/develop/so/scrap/build' CXX(target) Release/obj.target/addon/hello.o SOLINK_MODULE(target) Release/obj.target/addon.node COPY Release/addon.node make: Leaving directory '/home/imk/develop/so/scrap/build' gyp info ok
Note, in addition, pkg-config tells you that the correct include-path compiler to search for gstreamer-1.0 header files is:
/usr/include/gstreamer-1.0
not
/usr/incude/gstreamer-1.0/gst/
And we followed this advice in binding.gyp . Therefore, in your source code you will write, for example.
#include <gst/gst.h>
and not:
#include <gst.h>
Further
Now your compiler cannot find <gst/gstconfig.h>
One possible reason is that you definitely did not copy the necessary directory directories for your system:
pkg-config --cflags gstreamer-1.0
in the list of include_dirs your binding-gyp . Perhaps you just copied those from my example. My example giving directories:
-I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 \ -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
was launched on Ubuntu 17.04 in which gst/gstconfig.h is actually installed in /usr/include/gstreamer-1.0 . But on Ubuntu 16.04, for example: -
$ pkg-config --cflags gstreamer-1.0 -pthread -I/usr/include/gstreamer-1.0 \ -I/usr/lib/x86_64-linux-gnu/gstreamer-1.0/include -I/usr/include/glib-2.0 \ -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
we get an extra include directory:
/usr/lib/x86_64-linux-gnu/gstreamer-1.0/include
and gst/gstconfig.h really installed there. Make sure you use the correct ones include the directories that pkg-config report about your system and adjust binding.gyp if necessary.
If you used the correct pkg-config results, then it would seem that your gstreamer-1.0 The dev package has a defective gstreamer-1.0.pc file, pkg-config information. To get around this, ask your distribution manager to show you where the dev gst/gstconfig.h package is actually installed. For example. for Ubuntu 16.04:
$ dpkg -L libgstreamer1.0-dev | grep gst/gstconfig /usr/lib/x86_64-linux-gnu/gstreamer-1.0/include/gst/gstconfig.h
Then add the required path prefix (e.g. /usr/lib/x86_64-linux-gnu/gstreamer-1.0/include ) to include_dirs your binding.gyp .