1

I am trying to create a Node C++ module for the purpose of interfacing with the Steam api. The library file is ./steam/lib/linux64/libsteam_api.so, and header files are in ./steam.

I have created a small regular C++ file for testing, which successfully uses the Steam api, imported using #include "steam_api.h". I have complied and imported the shared library like this: g++ -L./steam/lib/linux64 -Wl,-rpath=./steam/lib/linux64 -Isteam -lsteam_api main.cpp

binding.gyp:

{
 "targets": [ {
  "target_name": "steam",
  "sources": [ "steam.cpp" ],
  "include_dirs": [
   "steam",
   "<!@(node -p \"require('node-addon-api').include\")"
  ],
  "cflags!": [ "-fno-exceptions" ],
  "cflags_cc!": [ "-fno-exceptions" ],
  "libraries": [ "./steam/lib/linux64/libsteam_api.so" ]
 } ]
}

When I try to compile the Node module using node-gyp, I get g++: error: ./steam/lib/linux64/libsteam_api.so: No such file or directory

How do I correctly import the shared library?

Daniel Herr
  • 19,083
  • 6
  • 44
  • 61

2 Answers2

1

After looking through some examples and a lot of trial and error, I was able to correct binding.gpy:

{
 "targets": [ {
  "target_name": "steam",
  "sources": [ "steam.cpp" ],
  "include_dirs": [
   "steam",
   "<!@(node -p \"require('node-addon-api').include\")"
  ],
  "cflags!": [ "-fno-exceptions" ],
  "cflags_cc!": [ "-fno-exceptions" ],
  "libraries": [
   "-lsteam_api",
   "-L../steam/lib/linux64",
   "-Wl,-rpath=./steam/lib/linux64"
  ]
 } ]
}

The libraries section needed to include the arguments similar to how they were invoked with g++, except "-L" differed from "-Wl,-rpath=" and the g++ inputs in needing to start one folder level up for some unknown reason.

Daniel Herr
  • 19,083
  • 6
  • 44
  • 61
0

It looks like node-gyp is changing the current directory as it runs, which invalidates your relative path. Either use an absolute path instead, or do some experimentation to find the new current directory and then use a path relative to that.

  • Changing the path caused the compile to work, but it still has trouble finding the library. Testing it with require('./build/Release/steam.node') results in Error: libsteam_api.so: cannot open shared object file: No such file or directory – Daniel Herr Jun 29 '19 at 05:17