R
R
Roman Chugunov2018-10-21 13:24:54
C++ / C#
Roman Chugunov, 2018-10-21 13:24:54

How to build a cross-distributive native node.js module?

Hello.
I am writing a module in C++ using NAN. Wrote it on Debian 9. Compiled, ran everything worked well. There I have gcc version 6.8.0.
On another laptop, I have CentOS 7. When I tried to run the application with my module on it, I got an error:

A Javascript error occurred in the main process
Uncaught Exception:
Error: Cannot open /tmp/.mount_figma-ijkRXB/resources/app.asar/main/binding.node: Error: /lib64/libstdc++.so.6:
/lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found

On CentOS 7 gcc version 4.8.5. Installing or building from source a newer version of gcc failed due to dependencies. CentOS 7 does not have new versions of other packages that the new version of gcc requires. Well, accordingly, rebuilding the module on CentOS did not work either.
Tell me how you can build a module and deploy all dependencies? So that you can use the module on any linux distribution, regardless of whether it has gcc and other necessary libs at all. Like for example linuxdeployqt does for Qt applications.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly, 2018-10-21
@Chalovik

Two options:
1) Link with the -static-libstdc++ flag. In this case, the static version of the lib will be linked into the executable. All other dependencies can also be linked statically. What is usually done for plugins. All in all, this is a very good option.
2) Supply the required version of the lib with the application, and link with '-Wl,-rpath,$ORIGIN/relative_path_to_lib_dir'. The same goes for other dependencies.
The first option may not work for some reasons (most likely it will not affect you):
1) If it is not known with which flags the host application executes dlopen on your plugin. This can be circumvented by introducing another layer without unnecessary dependencies, which will correctly execute dlopen.
2) Licenses. Something may be impossible to link statically, or it is possible, but with unfavorable conditions for you.
The second option can also be problematic. If the host application has already loaded a dependency whose name and version matches the name and version of the dependency your plugin needs, then the dependency for your plugin will not be loaded. This is not a problem if the dependencies are the same. But if you patch or your own dependencies, then you will have to rename them and use the soname flag. But then again, I'm not sure that this problem will affect you.
Welcome to the world of C++ :)
PS
Try writing your plugin in Rust, for example. Life is likely to get easier.

K
Kirill Kudryavtsev, 2018-10-21
@Deissh

As one of the options to use Docker for building, it will be possible to compile with the necessary packages and version of gcc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question