Mono Mathnet MKL Nativer provider not found - mono

I'm trying to use the Mkl native provider from mathdotnet with mono in Linux.
I'm using monodevelop and installed MathNet.Numerics and both MathNet.Numerics.MKL.Linux-x64 and -x86 packages via the build in NuGet package manager.
When I try this code, i get System.NotSupportedException: MKL Native Provider Not Found.
using System;
using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics;
namespace mdeveloptest
{
class MainClass
{
public static void Main (string[] args)
{
Control.UseNativeMKL ();
Matrix<double> a = DenseMatrix.OfArray(new double[,] { {1,2,3}, {4,5,6}, {7,8,9}});
Matrix<double> b = DenseMatrix.OfArray(new double[,] { {1,2,3}, {4,5,6}, {7,8,9}});
Console.WriteLine (a*b);
}
}
}
The MKL-packages provide a libiomp5.so and a MathNet.Numerics.MKL.dll file. In windows it was enough to copy these files to the output directory but it doesn't seem to be enough in Linux.
I'm also not sure if I need the x64 or x86 package or if mono somehow can choose the right one by itself.

Linux's ldconfig needs to know where to find the shared libraries (*.so) even if they are in the current directory of the executable. If you where running this mono app from the cmd and all your files (exe, dlls and SOs) are in the current directory, you would:
export LD_LIBRARY_PATH=${PWD}:$LD_LIBRARY_PATH
mono mdeveloptest.exe
In MonoDevelop / Xamarin Studio:
Open the Project options
Goto the Run / General panel
Add an Environment Variable
.
Variable | Value
LD_LIBRARY_PATH | ./
FYI: I have used ${PWD} as XS/MonoDevelop env vars and they get shell expanded correctly, it might be the way they are quoting the strings. As the poster had to use "./", I updated the answer.
FYI: OS-X's dyld includes the current directory by default and thus the DYLD_LIBRARY_PATH would not need to be set in this case.
Additional info:
From Math.NET Numerics: http://numerics.mathdotnet.com/MKL.html
Native assembly resolving is very different on Linux than on Windows,
simply putting the native libraries into the same folder as the
executable is not enough. The safe way is to edit /etc/ld.so.conf and
use ldconfig to tell where to look for the libraries. Alternatively
you could add the path to LD_LIBRARY_PATH or even just copy them to
/usr/lib.
From Linux Documentation Project:
Shared Libraries : http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

What version of Math.NET Numerics are you using? Since v3.6 it is supposed to look explicitly also in the output folder, even on Linux. You can also set Control.NativeProviderPath to make it look at another path as well. And yes, if you put both into an x64 and x86 subfolder, it will pick the right one automatically. See our documentation for Intel MKL for details.
Of course you can also set it up as shared library the Linux way with ldconfig, see Linux Interop with Native Libraries.

Related

Cannot open source file avr/io.h (dependency of hal.h) with Visual Studio Code on windows 10

I want to implement an embedded project using stm32F0 (arm-based) with VS Code. The project ran properly on other systems.
I Added C/C++ extension to visual studio
I installed a compiler for cortex-m0 arm: GNU Arm Embedded toolchain/gcc arm for windows.
Makefiles installed: binaries file + dependencies file
openOCD installed (open On Chip Debugger)
tasks.json (build instructions), c_cpp_properties.json (compiler path and IntelliSense settings) were created. I modified the Include path because my program includes header files that aren't in my workspace, and that is not in the standard library path.
c_cpp_properties.json file
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**" ,
"C:\\Users\\lib\\chibios\\ChibiOS-313416b8fda90d9973a749a0a35970956852c286\\os\\hal\\include",
"C:\\Users\\lib\\chibios\\ChibiOS-313416b8fda90d9973a749a0a35970956852c286\\os\\common\\ports\\ARM\\compilers\\GCC",
"C:\\Users\\lib\\chibios\\ChibiOS-313416b8fda90d9973a749a0a35970956852c286\\os\\nil\\include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "E:\\tools-vs\\gcc-arm-none-eabi-10-2020-q4-major\\bin\\arm-none-eabi-g++",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-arm",
"browse": {
"path": [
"E:\\tools-vs\\gcc-arm-none-eabi-10-2020-q4-major\\lib\\gcc\\arm-none-eabi\\10.2.1\\include"
]
}
}
],
"version": 4
}
After adding these paths, I still got errors:
#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit
cannot open source file "avr/io.h" (dependency of "hal.h")
As an embedded project has lots of libraries and dependencies, it is not possible to add paths of dependencies one by one. After solving and adding a path for one dependency, there should be another error.
Another problem is that I cannot even find the dependency avr/io.h by myself in the directory.
I used Keil before for other projects. When I compiled the code, it called all dependencies by itself. Before compiling, I didn't see dependencies on the tree section or any error for dependencies of header files.
But, how VS Code can find dependencies before compiling?
I also was wondering if I should add a path for main.cpp file and other C and CPP files in the configuration file of VS Code to solve these problems?
For debugging, I don't see any debugger in the list, though I installed openOCD and add the path in the environment variable
Much appreciated for any command or helpful resource, in advance.
Cannot open source file avr/io.h (dependency of hal.h)
You appear to be using ChibiOS whhich has a file hal.h which includes halconf.h which includes mcuconf.h. Clearly you appear to have an AVR port of ChibiOS where you need STM32 or ARM Cortex-M support.
But, how VS Code can find dependencies before compiling?
The same way as the compiler/pre-processor do, by having include paths configured, parsing the project files and accounting for any externally defined (command line) macros.
I also was wondering if I should add a path for main.cpp file and other C and CPP files in the configuration file of VS Code to solve these problems?
I believe it will parse project files in any case. It only needs to find the header files included in a source file to provide context for the parsing of the sourcefile.
For debugging, I don't see any debugger in the list, though I installed openOCD and add the path in the environment variable
That is an entirely different question - post a new question for that.
You have code for 8-bits AVR microcontrollers and you try to directly compile it using ARM toolchain. It will not work. You will need to rewrite this program (not only includes, but almost everything. Interrupt handlers, registers, even hardware architecture differs (Harvard/von Neumann)).
For the beginner, it is mission impossible.
Thank you for the answers.
Using Visual Studio instead of Visual Studio Code
Using the right toolchains (GCC: gcc-arm-none-eabi)
adding visualGDB plugin from sysProgs to VS
having IntelliSense configuration (The extension in VS finds paths after checking default location & uses the compiler we have on the pc to configure IntelliSense. If there is an error in include files, you can edit the IntelliSense to tell the C++ extension where the compiler is and include header files. But visualGDB will automatically find them)
having include paths configured
building the project
and rescanning solution
All of these steps solved the problem for me.

With Kotlin Native, building a windows exe, can I bundle libraries ( dlls ) into the exe?

Let's say I want to build a simple windows exe that does HTTP requests with curl.
( See example: https://github.com/JetBrains/kotlin-native/tree/master/samples/curl ).
The example above works, but in order for the exe to run, it needs to find libcurl-4.dll, either in the local dir, or e.g. in the installation dir ( e.g. C:\msys64\mingw64\lib ).
I would like to ship just the exe file, without having to provide the dll files separately. Is it possible to build the exe file with all the things it uses from the library (and transitive dependencies...) bundled into the exe file?
(This question is about if I can do this with a Kotlin 1.3.61 Native project, and how.)
I'm studying Kotlin too and it took many hours until I realize how to handle def file, includes and static library.
I made an example of how to use static library (curl with gzip and SSL support compiled with mingw) on kotlin-native. This way you dont need to dll files to be supplied with your app
https://github.com/carlosrafp/Libcurl-Kotlin-Native-standalone
On libcurl.def file you can see:
headers = curl/curl.h // path to curl header
libraryPaths = src/nativeInterop/cinterop // path to your static library
staticLibraries = libcurl.a // the static library
linkerOpts.mingw = -lws2_32 -lwldap32 // linking dependences
I based on the nice post of jonnyzzz:
https://jonnyzzz.com/blog/2018/10/29/kn-libcurl-windows/
You need to build the static libraries using mingw (libcurl, gzip) and msys2/mingw(openssl) to use with kotlin-native compiler
You can definitely do this for a static library(see this), but not for the .dll. About the shared library bundling, I would just recommend you to see this question. It's about the same but a bit generalized.

cmake always use my pc installed library instead of my target path

I get a project that was built for x86, and I am trying to make it work with mips. But I encounter problem when modifying the CMakelists.txt.
So here is the problem, the following code always use my PC's x86 library:
PKG_CHECK_MODULES(LIBCRYPTO REQUIRED libcrypto)
IF(LIBCRYPTO_FOUND)
INCLUDE_DIRECTORIES(${LIBCRYPTO_INCLUDE_DIRS})
LINK_DIRECTORIES(${LIBCRYPTO_LIB_DIRS})
ENDIF(LIBCRYPTO_FOUND)
I googled and found they always use system library first and can use find_package with NO_CMAKE_SYSTEM_PATH flag. But its not working and give me the following message. I don't know what its talking about..
Could not find a package configuration file provided by "libcrypto" with
any of the following names:
libcryptoConfig.cmake
libcrypto-config.cmake
Add the installation prefix of "libcrypto" to CMAKE_PREFIX_PATH or set
"libcrypto_DIR" to a directory containing one of the above files. If
"libcrypto" provides a separate development package or SDK, be sure it has
been installed.
My question is how to properly link a library to the path I assigned to and works like original piece of code?

How to enable eglfs plugin in Yocto setup? using yocto+meta-qt5 for Riotboard

Recently I just used fsl-community-bsp and meta-qt5 layer to generate the cross toolchain and the rootfs. I used "bitbake meta-toolchain-qt5" and "bitbake fsl-image-multimedia-full". Both fsl-community-bsp and meta-qt5 use jethro branch.
Following are some of my questions:
In the rootfs which I put in the “riotboard”, is qt5 library already in it? Do I need to compile the source of qt5 and copy it to the board
separately?---Now it's clear, the library are inside the rootfs;
I have set up the qtcreator: device, kit, qt version, compiler, debugger, also ssh connection, but when I run the application, qt says
“This application failed to start because it could not find or load the qt platform plugin xcb, available platform plugin are: eglfs, minimal, minimalegl, offscreen”.---It seems the error is fixed by me, modifying the PACKAGECONFIG[gles2]="-opengl es2 -eglfs -qpa eglfs,,virtual/libgles2 virtual/egl";
In the Jethro branch of meta-qt5, the qtbase.inc is missing, correct? I found on the internet, that I can modify the PACKAGECONFIG[gles] value, add –qpa eglfs.---It's into the qtbase_git.bb now;
I also found that in the Jethro branch, the serialport is also missing, but in our application, we need this function to handle the serial keyboard. How can we do now?---I find it now;
If I need to compile the qt5 source and copy all the folder to the riotboard, how can I set the path in the qtcreator to find the relevant library?---No need to do this;
Thank you very much!
To enable EGLFS, in local.conf add: DISTRO_FEATURES_remove = "X11 wayland"
1.You do not need to copy the qt5 library, you could follow this wandboard qt5 implementation here
In your machine, you need to enable Qt to run eglfs platform, in /etc/profile, add export QT_QPA_PLATFORM=eglfs or when you run an application; you need to add -platform eglfs. ie. helloworld -platform eglfs
There is no qtbase.inc; You could add PACKAGECONFIG_append_pn-qtbase = " eglfs xx xxx xxxx" to enable the configuration you need
There is qtserialport_git.bb in Jethro
As said, you do not copy the libraries and sources but instead tell Bitbake to do that for you. They will be moved to the corresponding places.

MonoGame not able to find dylib files, throwing DllNotFoundException

I have a project using MonoMac in Xamarin Studio. I'm using [DllImport ("rlimit")] to access a .dylib file. However, even though I have mapped rlimit to rlimit.dylib, a DllNotFoundException is still thrown.
The .dylib files are in the project and should be accessible, however they cannot be found.
I'm guessing that the files are either in the wrong place, or they aren't being detected for some reason.
You need to put the dylib anywhere mono can find it.
You can find out where mono looks for native libraries by doing this:
export MONO_LOG_LEVEL=debug
export MONO_LOG_MASK=dll
mono yourprogram.exe
and verbose lookup output will be printed to the terminal. On my system mono looks first in the directory where the executable is, so putting the dylib there is probably the easiest. Then mono asks the system to find the dylib (by trying to open it without a path). The system typically looks in /usr/lib and maybe a few other places (this is of course system-dependent), but in any case you can add a path for the system to look in by setting LD_LIBRARY_PATH to that path. In this case you'll do this:
export LD_LIBRARY_PATH=/path/to/dylib:$LD_LIBRARY_PATH
mono yourprogram.exe
Note that you do not need the .dllmap, mono will automatically append the appropiate suffix depending on the platform (.dylib on Mac, .so on Linux and .dll on Windows).