简体   繁体   English

node-gyp - 找不到库头

[英]node-gyp - not finding library headers

I'm trying to use a the gstreamer framework in my node addon. 我正在尝试在我的节点插件中使用gstreamer框架。 I had the following to my to my binding.gyp, but when i run the build command it, the console states that the header is not found. 我对我的binding.gyp有以下内容,但是当我运行build命令时,控制台声明找不到标题。 When i compile my gstreamer files outside of node-gyp, it compiles successfully. 当我在node-gyp之外编译我的gstreamer文件时,它成功编译。 Does anyone see something wrong with my binding file ? 有没有人看到我的绑定文件有问题?

console 安慰

hello.cc3:25: fatal error: gstreamermm.h: No such file or directory 

binding.gyp binding.gyp

{
  "targets": [
    {
      "target_name": "addon",
          "libraries": [
            "-lgstreamer-1.0", "-L/usr/inlcude/gstreamer-1.0/gst/"
          ],
      "sources": [ "hello.cc" ]
    }
  ]
}

compile command that works correctly, and that I'm trying to run 编译命令正常工作,我正在尝试运行

g++ main.c -o main `pkg-config --cflags --libs gstreamer-1.0`

Update: Following @Mike Kinghan binding.gyp 更新:关注@Mike Kinghan binding.gyp 在此输入图像描述

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 should include the libraries, specified in -l or absolute filename form, that you want to link. binding.gyp"libraries"元素应包含要链接的以-l或绝对文件名形式指定的库。

-lgstreamer-1.0 is one of those. -lgstreamer-1.0就是其中之一。 -L/usr/inlcude/gstreamer-1.0/gst/ is not. -L/usr/inlcude/gstreamer-1.0/gst/不是。 It is a linker option that will instruct the linker to search for libraries specified in -l form in the directory /usr/include/gstreamer-1.0/gst/ . 它是一个链接器选项,它将指示链接器在/usr/include/gstreamer-1.0/gst/目录中搜索以-l形式指定的库。

That is specifying a library search directory, so if it were needed, you should say so in the "library_dirs" element: 那是指定一个库搜索目录,所以如果需要,你应该在"library_dirs"元素中这样说:

"library_dirs": [
  "/usr/inlcude/gstreamer-1.0/gst/",
]

But you don't need it, because there are no libraries in /usr/inlcude/gstreamer-1.0/gst/ . 但是你不需要它,因为/usr/inlcude/gstreamer-1.0/gst/中没有库。 All the files under /usr/include are C or C++ header files, not libraries. /usr/include下的所有文件都是C或C ++头文件,而不是库。 Libraries are installed under /lib , /usr/lib or /usr/local/lib . 库安装在/lib/usr/lib/usr/local/lib

You say you can successfully compile a program with: 你说你可以成功编译一个程序:

g++ main.c -o main `pkg-config --cflags --libs gstreamer-1.0`

That works because as you may know, 这是有效的,因为你可能知道,

pkg-config --cflags --libs gstreamer-1.0

outputs the compiler and linker options needed to build a target that depends on gstreamer-1.0 输出构建依赖于gstreamer-1.0的目标所需的编译器和链接器选项

Let's have a look: 我们来看一下:

$ 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 let's use that information to write binding.gyp . 然后让我们使用该信息来编写binding.gyp (On your system it might differ from mine): (在您的系统上它可能与我的不同):

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"
        ],
        "libraries": [
            "-lgstreamer-1.0",
            "-lgobject-2.0",
            "-lglib-2.0"
        ],
        "sources": [ "hello.cc" ]
    }
  ]
}

(Have we forgotten the -pthread option emitted by pkg-config ? No. node-gyp passes it the compiler and linker by default) (我们忘记了pkg-config发出的-pthread选项吗?没有node-gyp默认情况下将它传递给编译器和链接器)

With this binding.gyp , your build should look something like mine: 使用此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   '-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 furthermore, pkg-config tells you that the correct compiler include-path to locate gstreamer-1.0 header files is: pkg-config请注意, pkg-config告诉您正确的编译器include-path来定位gstreamer-1.0头文件是:

/usr/include/gstreamer-1.0

not: 不:

/usr/incude/gstreamer-1.0/gst/

And we have followed that advice in our binding.gyp . 我们在binding.gyp遵循了这个建议。 Therefore in your source code you will write, eg 因此,在您的源代码中,您将编写,例如

#include <gst/gst.h>

and not: 并不是:

#include <gst.h>

Later 后来

Now your compiler cannot locate <gst/gstconfig.h> 现在你的编译器无法找到<gst/gstconfig.h>

One possible cause is that you didn't faithfully copy the necessary include-directories reported for your system by: 一个可能的原因是您没有忠实地复制为您的系统报告的必要包含目录:

pkg-config --cflags gstreamer-1.0

into the include_dirs list of your binding-gyp . 进入binding-gypinclude_dirs列表。 Possibly you just copied the ones 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 run on Ubuntu 17.04, in which gst/gstconfig.h is in fact installed in /usr/include/gstreamer-1.0 . 在Ubuntu 17.04上运行,其中gst/gstconfig.h实际安装在/usr/include/gstreamer-1.0 But on Ubuntu 16.04, for example:- 但是在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

we get the additional include directory: 我们得到额外的包含目录:

/usr/lib/x86_64-linux-gnu/gstreamer-1.0/include

and gst/gstconfig.h is indeed installed there. 确实安装了gst/gstconfig.h Check that you are using the correct include directories that pkg-config reports on your system and correct your binding.gyp if necessary. 检查您是否正在使用pkg-config在系统上报告的正确包含目录,并在必要时更正binding.gyp

If you were using the correct pkg-config results, then it would appear that your gstreamer-1.0 dev package has a defective gstreamer-1.0.pc file providing incorrect pkg-config info. 如果使用了正确的pkg-config的结果,那么它会出现你gstreamer-1.0开发包有缺陷gstreamer-1.0.pc文件提供不正确pkg-config信息。 To work around that, ask your distro's package manager to show you where the dev package really installed gst/gstconfig.h . 要解决这个问题,请让发行版的软件包管理器向您展示开发软件包真正安装的位置gst/gstconfig.h Eg for Ubuntu 16.04: 例如,对于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 (eg /usr/lib/x86_64-linux-gnu/gstreamer-1.0/include ) to the include_dirs of your binding.gyp . 然后将所需的路径前缀(例如/usr/lib/x86_64-linux-gnu/gstreamer-1.0/include )添加到binding.gypinclude_dirs中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM