Node-gyp/C++ import shared library (.so)

我的梦境 提交于 2020-01-03 16:56:59

问题


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

In my .cpp file I include the library like this

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

My binding.gyp looks as like this

{
  "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"
  ]
}

The compiling error is

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

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.


回答1:


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.

Updated the binding.gyp to

"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.



来源:https://stackoverflow.com/questions/50531237/node-gyp-c-import-shared-library-so

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!