Node-gyp/C ++导入共享库(.so)

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.