node c++ addon / v8 / custom dependency - c++

I am trying to build a node c++ addon on ubuntu using code::blocks. I have build a addon.node shared library that depends on another shared library dep.so . When creating my basid js file with
var addon = require(./addon.node);
it gives
Error: dep.so: cannot open shared object file: No such file or directory
at Error (native)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:367:17)
at require (module.js:386:17)
at repl:1:13
at REPLServer.defaultEval (repl.js:130:27)
at bound (domain.js:254:14)
at REPLServer.runBound [as eval] (domain.js:267:12)
at REPLServer.<anonymous> (repl.js:277:12)
My dep.so file is included while building addon.node and exists in the same build directory as addon.node
running ld addon.node it gives (among other things)
ld: warning: dep.so, needed by addon.node, not found (try using -rpath or -rpath-link)
ld: warning: cannot find entry symbol _start; not setting start address
addon.node: undefined reference to `v8::ObjectTemplate::SetInternalFieldCount(int)'
so, it seems I have two problems:
1) it can't find my own created dep.so library
2) it can't find v8 library (I guess this needs to be build somehow)
Any suggestions how to get this to work?
Cheers, Mike

nbind makes it easy in general to write Node.js bindings for libraries and libui-node is a practical example of using it, to create a cross-platform native UI. Its binding.gyp file shows how to successfully link with a library called libui placed in the root directory of the module (not the build directory).
On Windows:
"libraries": [
"<(module_root_dir)/libui.lib"
]
Linux:
'ldflags': [
'-Wl,-rpath,<(module_root_dir)',
],
"libraries": [
"<(module_root_dir)/libui.so"
]
OS X:
"xcode_settings": {
"OTHER_LDFLAGS": [
"-L<(module_root_dir)",
"-lui",
"-rpath",
"<(module_root_dir)"
]
}

Related

ROS personal global planner - undefined symbol: _ZN18base_local_planner12CostmapModelC1ERKN10costmap_2d9Costmap2DE

My setup is: ROS melodic, Ubuntu: 18.04
I want simulate turtlebot3 moving with my own global planner and have been following this tutorial to get started: http://wiki.ros.org/navigation/Tutorials/Writing%20A%20Global%20Path%20Planner%20As%20Plugin%20in%20ROS#Running_the_Plugin_on_the_Turtlebot. The tutorial seem to be made for ROS hydro, but as it was the best source of guidance I could find I hoped it would work. I have been using this turtlebot3 tutorial and commands to get started: https://emanual.robotis.com/docs/en/platform/turtlebot3/nav_simulation/
There is no problem having the robot navigate with 2D Nav Goal in rviz using the in-built planning packages, but when I try to run the the global path planner in my own package I get the following error when I try to launch the 'turtlebot3_navigation.launch' file:
[ INFO] [1661178206.728674676, 7.359000000]: global_costmap: Using plugin "static_layer"
[ INFO] [1661178206.742733426, 7.372000000]: Requesting the map...
[ INFO] [1661178206.945370142, 7.575000000]: Resizing costmap to 384 X 384 at 0.050000 m/pix
[ INFO] [1661178207.047423541, 7.676000000]: Received a 384 X 384 map at 0.050000 m/pix
[ INFO] [1661178207.053220010, 7.678000000]: global_costmap: Using plugin "obstacle_layer"
[ INFO] [1661178207.056864268, 7.685000000]: Subscribed to Topics: scan
[ INFO] [1661178207.079615282, 7.706000000]: global_costmap: Using plugin "inflation_layer"
/opt/ros/melodic/lib/move_base/move_base: symbol lookup error: /home/aut/catkin_ws/devel/lib//libmy_global_planner_lib.so: undefined symbol: _ZN18base_local_planner12CostmapModelC1ERKN10costmap_2d9Costmap2DE
[move_base-4] process has died [pid 625, exit code 127, cmd /opt/ros/melodic/lib/move_base/move_base cmd_vel:=/cmd_vel odom:=odom __name:=move_base __log:=/home/aut/.ros/log/f4c41f78-2225-11ed-befb-b8ca3a965376/move_base-4.log].
log file: /home/aut/.ros/log/f4c41f78-2225-11ed-befb-b8ca3a965376/move_base-4*.log
I ran c++filt on the symbol lookup error and got:
c++filt _ZN18base_local_planner12CostmapModelC1ERKN10costmap_2d9Costmap2DE
base_local_planner::CostmapModel::CostmapModel(costmap_2d::Costmap2D const&)
I've beeen using this code (https://github.com/ros-planning/navigation/blob/noetic-devel/carrot_planner/src/carrot_planner.cpp) and (https://github.com/ros-planning/navigation/blob/noetic-devel/carrot_planner/include/carrot_planner/carrot_planner.h) changing carrot_planner and CarrotPlanner to my_global_planner and MyGlobalPlanner, figuring that using some code is already/should already be working was a good way to avoid confusion about whether my code or something else caused errors.
My CMakeList.txt is looking like this currently:
cmake_minimum_required(VERSION 3.0.2)
project(my_global_planner)
find_package(catkin REQUIRED
actionlib
roscpp
rospy
std_msgs
)
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES my_global_planner
# CATKIN_DEPENDS other_catkin_pkg
# DEPENDS system_lib
)
include_directories(
include
${catkin_INCLUDE_DIRS}
)
add_library(my_global_planner_lib src/my_global_planner/my_global_planner.cpp)
I've been experimenting with it, adding stuff like:
find_package(catkin REQUIRED
COMPONENTS
angles
base_local_planner
costmap_2d
nav_core
pluginlib
roscpp
tf2
tf2_geometry_msgs
tf2_ros
)
and such in the catkin_packages also, but it doesn't seem to have worked and I've returned it to how it was. I've also tried adding more than just:
<buildtool_depend>catkin</buildtool_depend>
<build_depend>nav_core</build_depend>
<exec_depend>nav_core</exec_depend>
to my package.xml, but no luck there either.
I hope I've made the problem clear and provided the needed information without dumping a massive sheet of code here. I feel that I've exhausted all my options at this point and any help or guidance would be greatly appreciated.
From what the error shows, your file has found the corrected header file, however, when looking up the lib, there is no correlated lib file.
There could be many reasons for that, e,g
You have multiple incompatible versions of costmap2D, to solve it, just delete all cost map in both workspace and in /opt/ros. then reinstall the costmap2d with corrected branch https://github.com/ros-planning/navigation/tree/melodic-devel
Secondly, In your cmakelist, do include costmap_2d and navigation inside find_package
Also include costmap_2d and navigation in your manifest

Node-gyp Library not loaded: /usr/local/lib/libmtp.9.dylib

I have been attempting to make a nodejs-native-addon which uses libmtp to carry out certain functions. I have been successful in the building the app but the app is throwing Library not loaded: /usr/local/lib/libmtp.9.dylib. Referenced from: /path/build/Debug/nbind.node. Reason: image not found error when I try to run it on another macbook where the libmtp isn't installed.
This is my binding.gyp file:
{
"targets": [
{
"includes": [
"auto.gypi"
],
"sources": [
"src/native/mtp.cc"
],
"link_settings": {
"libraries": [
"-lmtp"
],
},
}
],
"includes": [
"auto-top.gypi"
],
}
I even attempted to include the dylib file in the libraries option
"link_settings": {
"libraries": [
"<(module_root_dir)/src/native/lib/libmtp.9.dylib"
]
}
but the app fails to start with the Library not loaded: /usr/local/lib/libmtp.9.dylib. Referenced from: /path/build/Debug/nbind.node. Reason: image not found error.
Any help will be appreciated.
The error is indicating that the library libmtp.9.dylib cannot be found in the standard library include path /usr/local/lib
Try setting the environment variable LD_LIBRARY_PATH to point to the location where you have the libmtp.9.dylib before running the node.
One solution would be to create a symlink in a known rpath like /usr/local/lib manually to your built library. Not ideal but it may provide a workaround for at least having successful builds in development.
ln -s <absolute_path>/src/native/lib/libmtp.9.dylib /usr/local/lib/libmtp.9.dylib
This allows the binding.gyp file to find the library without it needing to configure an rpath with whatever process is throwing the error. This is easier in my opinion than tracking down the binding.gyp trace.

libxlsxwriter with MinGW

For two days I have spent several hours trying to get libxlsxwriter to work with mingw on Windows. I followed the instructions to install and build the library, but every time I attempt to include the header files in one of my projects and use one of the function in the library, I end up getting the same error:
D:\Apps\CLion\bin\cmake\win\bin\cmake.exe --build C:\Users\Simon\CLionProjects\myexcel\cmake-build-debug --target all -- -j 4
[ 50%] Linking CXX executable myexcel.exe
D:/Apps/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles\myexcel.dir/objects.a(main.cpp.obj): in function `main':
C:/Users/Simon/CLionProjects/myexcel/main.cpp:4: undefined reference to `workbook_new'
D:/Apps/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Simon/CLionProjects/myexcel/main.cpp:5: undefined reference to `workbook_add_worksheet'
D:/Apps/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Simon/CLionProjects/myexcel/main.cpp:8: undefined reference to `worksheet_write_string'
D:/Apps/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/Simon/CLionProjects/myexcel/main.cpp:9: undefined reference to `workbook_close'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [CMakeFiles\myexcel.dir\build.make:85: myexcel.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:75: CMakeFiles/myexcel.dir/all] Error 2
mingw32-make.exe: *** [Makefile:83: all] Error 2
My code is very basic (it's pretty much one of the sample codes provided):
#include "xlsxwriter.h"
int main() {
lxw_workbook *workbook = workbook_new("myexcel.xlsx");
lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
int row = 0;
int col = 0;
worksheet_write_string(worksheet, row, col, "Hello me!", NULL);
return workbook_close(workbook);
}
I have tried several ways to get deploy mingw, but I've ultimately settled for msys2 as a platform to host mingw as I feel the *nix environments are beneficial when it comes to managing a multitude of packages and it comes with the needed zlib preinstalled.
For all it'S worth here's my toolchain configuration in CLion 2019.3
and here's my project configuration:
Any ideas what's wrong here? I am a newby as it relates to C/C++... help is very much appreciated!
EDIT:
I've tried to install the built files from the mys2 console with pacman pacman -Ss xlsx. From what it looks like, it's already installed. This is the output of the console:
$ pacman -Ss xlsx
mingw32/mingw-w64-i686-libxlsxwriter 0.9.4-1
A C library for creating Excel XLSX files (mingw-w64)
mingw32/mingw-w64-i686-python-openpyxl 3.0.2-1
A python library to read/write Excel 2007 xlsx/xlsm file (mingw-w64)
mingw32/mingw-w64-i686-python-xlsxwriter 1.2.7-1
A Python module for creating Excel XLSL files (mingw-w64)
mingw32/mingw-w64-i686-xlnt 1.4.0-1
User-friendly xlsx library for C++14 (mingw-w64)
mingw64/mingw-w64-x86_64-libxlsxwriter 0.9.4-1
A C library for creating Excel XLSX files (mingw-w64)
mingw64/mingw-w64-x86_64-python-openpyxl 3.0.2-1
A python library to read/write Excel 2007 xlsx/xlsm file (mingw-w64)
mingw64/mingw-w64-x86_64-python-xlsxwriter 1.2.7-1
A Python module for creating Excel XLSL files (mingw-w64)
mingw64/mingw-w64-x86_64-xlnt 1.4.0-1
User-friendly xlsx library for C++14 (mingw-w64)
I don't get it, frankly. There is no libxlsxwriter.so anywhere. I have the two files (libxlsxwriter.a, libxlsxwriter.dll) in the usr/local folder and in the home folder (where they have been built originally).
You can find the libxlsxwriter library as Msys2 package and install them using (from MinGW 64 shell) the following command:
pacman -S mingw-w64-x86_64-libxlsxwriter

Conflict Protobuf version when using Opencv and Tensorflow c++

I am currently trying to use Tensorflow's shared library in a non-bazel project, so I creat a .so file from tensorflow using bazel.
but when I launch a c++ program that uses both Opencv and Tensorflow, it makes me the following error :
[libprotobuf FATAL external/protobuf/src/google/protobuf/stubs/common.cc:78] This program was compiled against version 2.6.1 of the Protocol Buffer runtime library, which is not compatible with the installed version (3.1.0). Contact the program author for an update. If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library. (Version verification failed in "/build/mir-pkdHET/mir-0.21.0+16.04.20160330/obj-x86_64-linux-gnu/src/protobuf/mir_protobuf.pb.cc".)
terminate called after throwing an instance of 'google::protobuf::FatalException'
what(): This program was compiled against version 2.6.1 of the Protocol Buffer runtime library, which is not compatible with the installed version (3.1.0). Contact the program author for an update. If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library. (Version verification failed in "/build/mir-pkdHET/mir-0.21.0+16.04.20160330/obj-x86_64-linux-gnu/src/protobuf/mir_protobuf.pb.cc".)
Abandon (core dumped)
Can you help me?
Thank you
You should rebuild TensorFlow with a linker script to avoid making third party symbols global in the shared library that Bazel creates. This is how the Android Java/JNI library for TensorFlow is able to coexist with the pre-installed protobuf library on the device (look at the build rules in tensorflow/contrib/android for a working example)
Here's a BUILD file that I adapted from the Android library to do this:
package(default_visibility = ["//visibility:public"])
licenses(["notice"]) # Apache 2.0
exports_files(["LICENSE"])
load(
"//tensorflow:tensorflow.bzl",
"tf_copts",
"if_android",
)
exports_files([
"version_script.lds",
])
# Build the native .so.
# bazel build //tensorflow/contrib/android_ndk:libtensorflow_cc_inference.so \
# --crosstool_top=//external:android/crosstool \
# --host_crosstool_top=#bazel_tools//tools/cpp:toolchain \
# --cpu=armeabi-v7a
LINKER_SCRIPT = "//tensorflow/contrib/android:version_script.lds"
cc_binary(
name = "libtensorflow_cc_inference.so",
srcs = [],
copts = tf_copts() + [
"-ffunction-sections",
"-fdata-sections",
],
linkopts = if_android([
"-landroid",
"-latomic",
"-ldl",
"-llog",
"-lm",
"-z defs",
"-s",
"-Wl,--gc-sections",
"-Wl,--version-script", # This line must be directly followed by LINKER_SCRIPT.
LINKER_SCRIPT,
]),
linkshared = 1,
linkstatic = 1,
tags = [
"manual",
"notap",
],
deps = [
"//tensorflow/core:android_tensorflow_lib",
LINKER_SCRIPT,
],
)
And the contents of version_script.lds:
{
global:
extern "C++" {
tensorflow::*;
};
local:
*;
};
This will make everything in the tensorflow namespace global and available through the library, while hiding the reset and preventing it from conflicting with protobuf.
(wasted a ton of time on this so I hope it helps!)
The error indicates that the program was complied using headers (.h files) from protobuf 2.6.1. These headers are typically found in /usr/include/google/protobuf or /usr/local/include/google/protobuf, though they could be in other places depending on your OS and how the program is being built. You need to update these headers to version 3.1.0 and recompile the program.
This is indeed a pretty serious problem! I get the below error similar to you:
$./ceres_single_test
[libprotobuf FATAL google/protobuf/stubs/common.cc:78] This program was compiled against version 2.6.1 of the Protocol Buffer runtime library, which is not compatible with the installed version (3.1.0). Contact the program author for an update. If you compiled the program yourself, make sure that your headers are from the same version of Protocol Buffers as your link-time library. (Version verification failed in "/build/mir-pkdHET/mir-0.21.0+16.04.20160330/obj-x86_64-linux-gnu/src/protobuf/mir_protobuf.pb.cc".)
terminate called after throwing an instance of 'google::protobuf::FatalException'
Aborted
My workaround:
cd /usr/lib/x86_64-linux-gnu
sudo mkdir BACKUP
sudo mv libmirprotobuf.so* ./BACKUP/
Now, the executable under test works, cool. What is not cool, however, is that things like gedit no longer work without running from a shell that has the BACKUP path added to LD_LIBRARY_PATH :-(
Hopefully there's a better fix out there?
The error complains about the Protocol Buffer runtime library, which is not compatible with the installed version. This error is coming from the GTK3 library. GTK3 use Protocol Buffer 2.6.1. If you use GTK3 to support Opencv, you get this error. The easiest way to fix this, you can use QT instead of GTK3.
If you use Cmake GUI to install Opencv, just select QT support instead of using GTK3. You can install QT using the following command.
sudo apt install qtbase5-dev
rebuild libprotobuf with -Dprotobuf_BUILD_SHARED_LIBS=ON
then make install to cover the older version

Derelict3 D bindings on OS X

I just want to make a little test with GLFW3 D binding.
I create a new package using
dub init glfw3Test
Then I wrote a little test in glfw3Test\source\app.d
import derelict.glfw3.glfw3;
void main()
{
// Load the GLFW 3 library.
DerelictGLFW3.load();
if(DerelictGLFW3.isLoaded)
{
// Do something cool!
}
}
And I modified the default JSON with:
{
"name": "glfw3Test",
"dependencies":
{
"derelict-glfw3": "~master"
},
"configurations": [
{
"name": "glfw3Test",
"targetType": "executable"
}
]
}
I built with dub build, everything went fine, but when I tred to launch the executable I got the following errors:
derelict.util.exception.SharedLibLoadException#../../../.dub/packages/derelict-util-1.0.2/source/derelict/util/exception.d(35): Failed to load one or more shared libraries:
libglfw.3.dylib - dlopen(libglfw.3.dylib, 2): image not found
libglfw3.dylib - dlopen(libglfw3.dylib, 2): image not found
I have also tried to compile my application manually without using DUB, but I got always the same problem.
It seems to look for the GLFW3 shared library, but I was thinking that the lib is statically linked by the built process.
I am on OS X 10.10 with Xcode 6 installed (DMD compiler 2.065)
I've noticed that the default make process of GLFW3 (using cmake) does not create the dylib files. So I rebuilt GLFW with the following option:
cmake -D BUILD_SHARED_LIBS=ON
And then I made a make install, so now the file libglfw.dylib is correctly installed in /usr/local/lib
Thank to #duselbaer for make me noticed this problem.