安慰
hello.cc3:25: fatal error: gstreamermm.h: No such file or directory
binding.gyp
{ "targets": [ { "target_name": "addon","libraries": [ "-lgstreamer-1.0","-L/usr/inlcude/gstreamer-1.0/gst/" ],"sources": [ "hello.cc" ] } ] }
编译命令正常工作,我正在尝试运行
g++ main.c -o main `pkg-config --cflags --libs gstreamer-1.0`
解决方法
Does anyone see something wrong with my binding file?
是:
"libraries": [ "-lgstreamer-1.0","-L/usr/include/gstreamer-1.0/gst/" ],
binding.gyp中的“libraries”元素应包含在-l或中指定的库
绝对文件名表单,您要链接.
-lgstreamer-1.0就是其中之一. -L / USR / inlcude / gstreamer的-1.0 / GST /
不是.它是一个链接器选项,用于指示链接器进行搜索
对于在/usr/include/gstreamer-1.0/gst/目录中以-l形式指定的库.
那是指定一个库搜索目录,所以如果需要,你应该这样说
“library_dirs”元素:
"library_dirs": [ "/usr/inlcude/gstreamer-1.0/gst/",]
但是你不需要它,因为/usr/inlcude/gstreamer-1.0/gst/中没有库.
/usr/include下的所有文件都是C或C头文件,而不是库.图书馆
安装在/ lib,/usr/lib或/usr/local / lib下.
你说你可以成功编译一个程序:
g++ main.c -o main `pkg-config --cflags --libs gstreamer-1.0`
这是有效的,因为你可能知道,
pkg-config --cflags --libs gstreamer-1.0
输出构建依赖的目标所需的编译器和链接器选项
gstreamer的-1.0
我们来看一下:
$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
然后让我们使用该信息来编写binding.gyp. (在您的系统上它可能与我的不同):
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" ],"-lgobject-2.0","-lglib-2.0" ],"sources": [ "hello.cc" ] } ] }
(我们忘记了pkg-config发出的-pthread选项吗?没有node-gyp传递
它默认是编译器和链接器)
使用此binding.gyp,您的构建应该看起来像我的:
$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 '/usr/share/node-gyp/addon.gypi',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
另请注意,pkg-config会告诉您正确的编译器包含路径
找到gstreamer-1.0头文件是:
/usr/include/gstreamer-1.0
不:
/usr/incude/gstreamer-1.0/gst/
我们在binding.gyp中遵循了这个建议.因此
在您的源代码中,您将编写,例如
#include <gst/gst.h>
并不是:
#include <gst.h>
后来
现在你的编译器找不到< gst / gstconfig.h>
一个可能的原因是你没有忠实地复制
为您的系统报告的必要包含目录:
pkg-config --cflags gstreamer-1.0
进入binding-gyp的include_dirs列表.可能是你
刚从我的例子中复制了那些.我的例子,给出目录:
-I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 \ -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
在Ubuntu 17.04上运行,实际上是gst / gstconfig.h
安装在/usr/include/gstreamer-1.0中.但在Ubuntu 16.04上,
例如:-
$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
我们得到额外的包含目录:
/usr/lib/x86_64-linux-gnu/gstreamer-1.0/include
确实安装了gst / gstconfig.h.检查您是否正在使用
pkg-config在您的系统上报告的正确包含目录
必要时纠正你的binding.gyp.
如果你使用正确的pkg-config结果,那么它会显示你的
gstreamer-1.0 dev软件包有一个有缺陷的gstreamer-1.0.pc文件提供错误
pkg-config信息.要解决这个问题,请让发行包的经理向您展示
dev包真正安装在哪里gst / gstconfig.h.例如.对于Ubuntu 16.04:
$dpkg -L libgstreamer1.0-dev | grep gst/gstconfig /usr/lib/x86_64-linux-gnu/gstreamer-1.0/include/gst/gstconfig.h
然后添加所需的路径前缀(例如/usr/lib/x86_64-linux-gnu/gstreamer-1.0/include)到binding.gyp的include_dirs.