ROS getPath() command problematic when using ROS as a stand alone library - c++

As the title mentions, I am using ROS as a stand-alone library in C++.
That means I import ROS as a lib and catkin is not used.
Now, I want to read a .yaml config file. One would expect this to work:
std::string pkg_loc = ros::package::getPath("sample_name");
It just seems to be problematic with ROS being used as a lib.
Directions to add catkin-related lines to my CMAKE file don't work and I keep getting this error:
error while loading shared libraries: librospack.so: cannot open shared object file: No such file or directory
Any ideas on a better way for me to do this?
Things I've tried so far:
I did include roslib in my set(ROS_LIBS ...) line of CMAKE.
I have this in my .bashrc export LD_LIBRARY_PATH=/opt/ros/noetic/lib
I do of course have #include <ros/package.h>
I'm using ROS Noetic, CMAKE 3.16, Ubuntu 20.

Related

compiling CGAL draw_polygon and linking qt5

I am trying to learn meshing algorithm for CFD puposes and I found CGAL to be a good library to learn everything from ground. My vcpkg cgal[qt5] installation failes due to some problem in installing boost. But other library installation works. I also tried to follow this tutorial but OpenGR and libpointmatcher library generation fails and results cmake error. So I have to setup everything manually. I am using Visual Studio 2022 and Qt5.15.2. I have qt extension downloaded and configured in visual studio. I have also QTDIR variable created in enviroment variables and Qt bin directory in system path.
What I did is as follows-
(1). first I created an empty console application called polygon and added various example code provided by cgal as a source and configuration x64, Release. changed
(2). created a folder library inside solution directory and extracted downloaded cgal-5.5.zip(has include, data, demo, etc ....) to library directory and added $(SolutionDir)library\cgal-5.5\include to additional include path in property manager.
(3). downloaded boost_1_80 from boost.org and compiled with the foolowing steps-
.\bootstrap
open project-config.jam and add-
using mpi ;
using python ;
run the command-
.\b2 --build-dir=build\x64 address-model=64 threading=multi --stagedir=stage/x64 --toolset=msvc -j 16 link=static,shared runtime-link=static,shared --variant=debug,release
added the boost_1_80 folder in include path and stage/x64/lib to additional library directory.
(4). I have built gmp and mpfr with vcpkg with .\vcpkg install gmp:x64-windows-static & .\vcpkg install mpfr:x64-windows-staticcommand and copied the folders gmp_x64-windows-static and mpfr_x64-windows-static to the library directory. I added include and lib folder of both library to respective path and in linker->additional dependency included the two lib file gmp.lib and mpfr.lib
(5). copied images, meshes, points_3 folder from data to solution directory
I can add eigen3, zlib to my project using the same process and all the examples I tried depend on the above libraries compiled and ran properly.
The problem comes when I try to do examples involves qt5. For example program draw_polygon.c-
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/draw_polygon_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Polygon_2<K> Polygon_2;
typedef CGAL::Point_2<K> Point;
int main()
{
// create a polygon and put some points in it
Polygon_2 p;
p.push_back(Point(0,0));
p.push_back(Point(4,0));
p.push_back(Point(4,4));
p.push_back(Point(2,2));
p.push_back(Point(0,4));
CGAL::draw(p);
return EXIT_SUCCESS;
}
I tried following this tutorial but it's made for older version of Qt(Qt4) and Qt5 does not have Qt folder(..\path to\Qt<QT-version>\include) inside includes. This program does not any form file but I added the rest of the includes and lib files accordingly. When I try to compile, it says CGAL_USE_BASIC_VIEWER not defined. Given in this article if I write #define CGAL_USE_BASIC_VIEWER before the includes the generated are like -
Then I tried doing from qt empty project in visual studio interface which still gives -
Obviously my linking failed. How do I fix it for my case? I have went through several other articles none had definite answers.

Using Armadillo C++ library in Swift 5

I'm trying to use Armadillo C++ library in my swift code to create sinusoidal curved arrow. Earlier it worked well with Objective C. But when I'm trying to do the same implementation in Swift, it's showing 'armadillo' file not found error.
I've downloaded the file from https://github.com/gadomski/armadillo/tree/master/branch-5.600/include path and copied both armadillo_bits folder and armadillo file into the project.
I've created a Objective C++ Wrapper around the C++ class too.
Objective C++ Wrapper DrawSinusoidal.h file
#import <Foundation/Foundation.h>
#interface DrawSinusoidal : NSObject
+(NSArray *)bezierPathsForPoints:(NSArray *)points;
Objective C++ Wrapper DrawSinusoidal.mm file
#import "DrawSinusoidal.h"
#import "DrawSinusoidalMath.h"
#implementation DrawSinusoidal
+(NSArray *)bezierPathsForPoints:(NSArray *)points {
...
}
C++ file - DrawSinusoidalMath.h
#include "armadillo"
std::vector<std::vector<arma::vec2>> bezierPathsForPoints(const std::vector<arma::vec2> &points);
C++ file - DrawSinusoidalMath.cpp file
#include <iostream>
#include "DrawSinusoidalMath.h"
using namespace arma;
std::vector<arma::vec2> bezierPathsForPoints(const arma::mat &tValues, const std::vector<arma::vec2> &points)
{
...
...
return points
}
Finally I found the solution to it. Sharing the steps which I followed.
We need to install the pre-built Armadillo packages to macOS which can be installed via MacPorts or HomeBrew
I installed using HomeBrew.
$ brew install armadillo
Once it is completed, please keep a note on the installed path from the last line.
In my machine, it is installed on path /usr/local/Cellar/armadillo/10.5.1
Next, we need to provide the Header Search Paths.
Headers are available in below location, so just copy the path and paste in Xcode.
/usr/local/Cellar/armadillo/10.5.1/include/armadillo_bits
Next, we need to link the libarmadillo.dylib library that is available in the installed path to the sdk path in the Xcode. Open terminal and type following command.
sudo ln -s /usr/local/Cellar/armadillo/10.5.1/lib/libarmadillo.dylib /Applications/Xcode_12.4.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.4.sdk/usr/lib/libarmadillo.dylib
Once done, now you can go to Targets > Build Phases > Link Binary with Libraries
You should see libarmadillo.dylib
Select and add it to your project.
Final step.. Copy armadillo text file and armadillo_bits folder, from below path to the project.
/usr/local/Cellar/armadillo/10.5.1/include
That's it.. The setup is over and you can use the Armadillo library in C++ files inside Objective-C/Swift projects.

How to use external library in a LLVM pass

I want to use boost graph library in one of the LLVM passes I am working on. Boost graph library is header only. So usually I can use it as -I<path to boost source>. My question is how to use it inside LLVM source tree (inside lib/Transforms/MyPass).
I tried the following.
First I tired adding include directory to my pass's CMakeLists.txt like so,
target_include_directories(LLVMMyPass "<path to boost headers>")
Next I tried to change the CPP_FLAGS,
set(CPP_FLAGS "${CPP_FLAGS} -I<path to boost headers> ")
Both didn't work. I keep getting the error.
fatal error: boost/graph/graph_traits.hpp: No such file or directory
#include "boost/graph/graph_traits.hpp"
Update : I tried using -DCMAKE_CXX_FLAGS=-I<path to boost> in cmake command. That also did not help.
system-wide installation of boost solved the problem
sudo apt-get install libboost-all-dev

Why does CMake Fail to Link Libbitcoin C++?

I have recently installed CMake in order to write code to make use of Libbitcoin in C++ but I am having a hard time, I was trying to build the example code on GitHub here. And it haters been going terribly. I can't manage to link the library right in CMake, here is my code. I read and people were saying that I should try Autoconf but I have no idea how to even start that as I know nothing about Autoconf. I have CMake 3.16, and installed Libbitcoin with brew but alias were made in /usr/local/include for the library, I am on Mac OS X 10.15. The CMake runs fine but when running "make", it responds with:
Scanning dependencies of target CreateAddr
main.cxx:1:10: fatal error: bitcoin/bitcoin.hpp: No such file or directory
1 | #include <bitcoin/bitcoin.hpp>
| ^~~~~~~~~~~~~~~~~~~~~
Here is my CMake text:
Please all help is appreciated I am beyond lost.
It is hard to be sure without knowing the specifics of your installation, but it appears that your include directory paths may be overlapping with what is specified for the header in main.cxx. The include_directories() call tells the compiler to include headers from this directory:
/usr/local/include/bitcoin
Then, in main.cxx, you're including the file with bitcoin/bitcoin.hpp. Combining these suggests the file is located here:
/usr/local/include/bitcoin/bitcoin/bitcoin.hpp
The error states the header could not be found, so perhaps you meant to locate it here:
/usr/local/include/bitcoin/bitcoin.hpp
In that case, just remove the relative directory path from the main.cxx file, like this:
#include <bitcoin.hpp>
Also, you want to link to your libbitcoin library correctly. Using link_directories() is not recommended. Instead, you can specify the full path to your libbitcoin library directly in the call to target_link_libraries(). The library may not be located in /usr/local/include/bitcoin. With these changes, the last few lines in your CMake would look something more like this:
include_directories(/usr/local/include/bitcoin)
add_executable(CreateAddr main.cxx)
target_link_libraries(CreateAddr PUBLIC /your/path/to/libs/libbitcoin.so)

Link library OpenSubdiv with CMake

I am trying to make a C++ program that uses the OpenSubdiv library from Pixar: https://github.com/PixarAnimationStudios/OpenSubdiv
I have managed to build the library, including the "tutorials", which uses the library.
Both OpenSubdiv and my own program is built with CMake (which I have some, but not much experince with). For testing purposes, I have a project folder where my C++ code lies, and I inside this folder I also have an OpenSubdiv folder where I have built the library in OpenSubdiv/build. The C++ code That I am using for testing purposes is identical to one of the tutorials provided by pixar with opensubdiv, called "far_tutorial_0.cpp". This tutorial compiles and work fine inside the Opensubdiv folder, with the very long and complex CMake script intended to install the entire library. However, when I move it out of the Opensubdiv folder, and try to compile with a simple CMake script, I get problems. This is the CMake script that I use:
cmake_minimum_required (VERSION 2.6)
project (test)
add_executable(test test.cpp)
include_directories(OpenSubdiv/build)
target_link_libraries(test osdCPU)
This manages to compile the code without any error messages, but when I try to execute the code, it says "error while loading shared libraries: libosdCPU.so.3.0.0.beta: cannot open shared object file: No such file or directory".
I have tried change the library name to "osdCPU.so.3.0.0.beta" (which gives an error while compiling), and I have tried using both library names (which gives the same error). The file "libosdCPU.so.3.0.0.beta" is inside the OpenSubdiv/build/lib folder, right next to "libosdCPU.so".
Does anybody know what's wrong?
You also have to provide the location of the library osdCPU with the CMake command link_directories.
Moreover, I encourage you to formalize your code with specific variables like this (including a cache variable you can modify through the command ccmake) :
set(osdCPU_PATH_DEFAULT "/default/path/to/osdCPU")
set(osdCPU_PATH "${osdCPU_PATH_DEFAULT}" CACHE PATH "Path to osdCPU")
set(osdCPU_INCLUDE_DIRS ${osdCPU_PATH}/include)
set(osdCPU_LIBRARY_DIRS ${osdCPU_PATH}/lib)
set(osdCPU_LIBRARIES osdCPU)
Then you can call
include_directories(${osdCPU_INCLUDE_DIRS})
link_directories(${osdCPU_LIBRARY_DIRS})
# ...
target_link_libraries(test ${osdCPU_LIBRARIES})