Node-gyp/C ++导入共享库(.so) [英] Node-gyp/C++ import shared library (.so)

查看:371
本文介绍了Node-gyp/C ++导入共享库(.so)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

导入共享库(.so)似乎不是一件容易的事.我试图按照此帖子中的说明进行操作,但我确实不能得到它的工作.没有库 RF24 的构建正在运行.遵循其构建说明,该说明在/usr/local/lib文件夹

Importing a shared library (.so) doesn't seem to be an easy task. I tried to follow the instructions in this post, but I really can't get it to work. Building without the library RF24 is working. Followed their build instructions which produced the following filesets in the /usr/local/lib folder

librf24-bcm.so        librf24.so        librf24.so.1     librf24.so.1.3  
librf24.so.1.3.1      node_modules      python2.7        python3.5

在我的.cpp文件中,我包括了这样的库

In my .cpp file I include the library like this

#include <RF24.h> // also tested "" instead of <>

我的 binding.gyp 看起来像这样

{
  "targets": [
    {
      "includes":     [ "../auto.gypi"               ],
      "sources":      [ "../../src/myfile.cpp"       ],
      "include_dirs": [ "../../src"                  ],
      "library_dirs": [ "/usr/local/lib"             ],
      "libraries":    [ "-llibrf24"                  ],
      "cflags!":      [ "-fno-exceptions"            ],
      "cflags":       [ "-std=c++11", "-fpermissive" ],
      "cflags_cc!":   [ "-fno-rtti"                  ] 
    }
  ],
  "includes": [
    "../auto-top.gypi"
  ]
}

编译错误是

myfile.cpp:2:18: fatal error: RF24.h: No such file or directory

我还尝试使用部分中的文件完整名称,例如librf24.so.1.3.1,并且没有-l标志.还将 library_dirs 条目切换为 include_dirs .还是一样的错误.

I also tried using the files complete names in the libraries section, e.g. librf24.so.1.3.1, and without the -l flag. Also switched the library_dirs entry to include_dirs. Still the same error.

推荐答案

根据此文章我能够弄清楚. RF24版本还将相应的头文件写入了/user/local/include/RF24.

According to this article I was able to figure it out. The RF24 build also has written the according header files to /user/local/include/RF24.

binding.gyp 更新为

"include_dirs": [
  "../../src",
  "/usr/local/include/RF24"
],
"libraries": [
  "/usr/local/lib/librf24.so.1.3.1"
]

至少该插件在编译时没有错误和警告.

At least the addon is compiling without errors and warnings.

这篇关于Node-gyp/C ++导入共享库(.so)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆