Using Armadillo C++ library in Swift 5 - c++

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.

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.

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

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.

Installing the FFTW3 library on Windows 10 using Code::Blocks (C++)

I want to install the FFTW3 library in my system which runs on Windows 10. My compiler is the minGW GCC 10.1 and I am using Code::Blocks.
I have downloaded the 64bit version from http://www.fftw.org/install/windows.html and unzipped it in C:\Program Files (x86)\CodeBlocks\myLibraries\FFTW3.
Then I followed the steps described here https://www.learncpp.com/cpp-tutorial/a3-using-libraries-with-codeblocks/. In step 4 it says "Tell the linker where to look for the library file(s) for the library."
Since there is no .lib file, it had to be created. I copied the libfftw3-3.def file and pasted it inside the bin folder of the mingw64 compiler, so that the dlltool can be used. Note that inside the same bin folder there exists the as.exe executable. I added this directory, namely C:\Users\User\Downloads\minGW_GCC_10_1\mingw64\bin to system PATH as described in MinGW dlltool creates empty file.
Then I opened the cmd window as admin and executed dlltool -v -d nlib32.def -l nlib32.lib. The 2KB libfftw3-3.lib file was created inside the compiler's bin folder.
Then, again, I followed the steps that are described in the link I provided above. For convinience, I am posting the steps directly below.
Once per library:
Acquire the library. Download it from the website or via a package manager.
Install the library. Unzip it to a directory or install it via a package manager.
Tell the compiler where to look for the header file(s) for the library.
Here I set the path to be C:\Program Files (x86)\CodeBlocks\myLibraries\FFTW3
Tell the linker where to look for the library file(s) for the library.
Here I set the path to be C:\Users\User\Downloads\minGW_GCC_10_1\mingw64\bin
Once per project:
Tell the linker which static or import library files to link.
Again the path was set to C:\Users\User\Downloads\minGW_GCC_10_1\mingw64\bin
#include the library’s header file(s) in your program.
Make sure the program know where to find any dynamic libraries being used.
When I execute the following code
#include <iostream>
#include <fftw3.h>
int main(){
int N = 100;
fftw_complex *in;
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
}
I am getting the following error: "Undefined reference to '__imp_fftw_malloc' ".
I don't know what I am doing wrong so that the compiler cannot find the function that I am calling, but I guess that the problem is in step 7, that is in the "Make sure the program know where to find any dynamic libraries being used." step. Note that this is the first time I had to deal with dynamic-link libraries etc so I am still confused.
I managed to make your code run in three simple steps (I suppose you have dowloaded and extracted FFTW properly and installed Code::Blocks too):
Indicate the FFTW directory so the header fftw3.h can be read. Build options > Search directories > Compiler and specify where the header file is. To me it's C:\Program Files\FFTW.
Copy the libfftw3-3.dll file from the FFTW directory to next to the .exe of your application. Tp me it's C:\projets\fftwEx\bin\Debug.
Copy and rename the libfftw3-3.dll file in the original installed directory to libfftw3-3.dll.a. Then indicate it's path in Build options > Linker settings > Link libraries. To me it's C:\Program Files\FFTW\libfftw3-3.dll.a.

dyld: Library not loaded: /usr/local/opt/jpeg/lib/libjpeg.9.dylib OpenCV C++ MacOS

I've been trying to make OpenCV (3.4.0) work on MacOS (10.11.6) with C++.
I've tried various ways for the installation, but ended up "succeeding" by following this guide.
I am now trying to run the following example project in CLion:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( )
{
Mat image;
image = imread("image1.jpg", CV_LOAD_IMAGE_COLOR);
waitKey(0);
return 0;
}
The project builds fine, but when I try to run it I get the following error:
dyld: Library not loaded: /usr/local/opt/jpeg/lib/libjpeg.9.dylib
I've been looking around and the only related problems I could find were in connection with PHP.
Any sort of help or pointer in the right direction is highly appreciated!
Many thanks in advance!
OpenCV requires the libjpeg library to read your jpg file, and it is dynamically loaded (like a DLL) when you run your program. The program searches that dynamic library at a predefined path - /usr/local/opt/jpeg/lib/libjpeg.9.dylib, and most likely you don't have this file there.
The first step is to find this library on your computer, which you can do by running:
sudo find / -name 'libjpeg.*'
If nothing is found (like it happened to me), you have several options: build the library from source code, find a pre-built library and download it, or install it from a package manager (like brew or MacPorts). Probably I would try brew first. Note: you probably need version 9 of the libjpeg library.
brew install libjpeg command worked for me. (you need to install brew first).
Step 2: when you get the library, you need to make sure that the program can find it. Usually there's a way to override the hardcoded path like /usr/local/opt at build time using some build script variable somewhere in the OpenCV build scripts. An easier way might be to either install it where it expects it to be (at /usr/local/opt), or make a symlink from that path to a real location.
I've used brew and it actually installed it at the expected path:
bash-3.2$ pwd
/usr/local/opt/libjpeg/lib
bash-3.2$ ls
libjpeg.9.dylib libjpeg.a libjpeg.dylib pkgconfig
bash-3.2$ brew info libjpeg
jpeg: stable 9c (bottled)
Image manipulation library
http://www.ijg.org
/usr/local/Cellar/jpeg/9c (21 files, 724.6KB) *

Can't build C++ project with XLNT library

I am trying to build a sample project using the XLNT-Library under Windows 8 using MinGW g++.
The code is the sample code found in the github Documentation:
#include <xlnt/xlnt.hpp>
int main()
{
xlnt::workbook wb;
xlnt::worksheet ws = wb.active_sheet();
ws.cell("A1").value(5);
ws.cell("B2").value("string data");
ws.cell("C3").formula("=RAND()");
ws.merge_cells("C3:C4");
ws.freeze_panes("B2");
wb.save("example.xlsx");
return 0;
}
I downloaded the library as a zip file, extracted it and copied the folder [xlnt-master-root]\include\xlnt into the folder where my main.cpp resides and then tried to compile it with this command:
g++ -std=c++14 -lxlnt -Ixlnt/include .\excelTest.cpp -o excelTest.exe
But this results in the following error:
c:/users/s/documents/myprogramms/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe:
cannot find -lxlnt
I also tried copying the [xlnt-master] folder to the main.cpp location and tried to compile it again with the same result.
I can program in C++ but I have not worked with libraries before.
Can you please give me a hint how to use and compile the project with the library correctly?
FYI: I also tried building the library with with cmake as found here.
Although cmake was a success, make -j8 won't do anything because no Makefile is created in the build directory.
Maybe I went wrong here?
Thanks for your help...
using the lasted visual studio 2017,you can build the xlnt library automatic.
you can download the library below:
https://1drv.ms/f/s!AvyYANq3dYDem1g9MtINWWw7CyTH