Install libraries into MSYS2 from source - opencv

I have installed MSYS2 along with mingw64 on windows.
How do I install an application or library (in this case OpenCV) from the source code into mingw64 in the same way as pacman does, ideally using the CMAKE-GUI (due to a number of options to set)?
I have tried using
Use CMake-Gui to generate a mingw-makefile, with an additional DCMAKE_INSTALL_PREFIX:PATH entry.
Running mingw64 make installed
The code compiles fine but then installing into the CMAKe build directory4
MSYS pkg-manager can not see the library (opencv)

pacman for MSYS2 is an MSYS2 port of the ArchLinux package manager,
pacman.
To make an application or library installable "in the same way as pacman",
and so that pacman can see it, you need to make a pacman package
of it: here is the documentation

Related

Problem using opencv in visual studio code

I installed openCV and vsc sees this import. However, when the program executes, an error pops up.
I have no idea where the bug is
make sure you select the right interpreter (or virtual environment)
re-select python interpreter in VSCode
reinstall the opencv library in the right interpreter:
pip3 install --force-reinstall opencv-contrib-python
also, you can use Anaconda to manage your packages

What is the proper way of adding a local dependency (openCV) in Meson?

I am using OpenCV in one of my projects. Until now, I was using version 3 under Ubuntu 18.04, so in my meson.build I had:
... dependencies: [dependency('opencv')])
Now, I've compiled OpenCV 4 from source and installed to the default dir, /usr/local/, and changed my meson.build to:
... dependencies: [dependency('opencv4')])
Resulting in a not found error (despite this works with Ubuntu 20.04 and the package from the official repos, which is version 4.2). How should I specify the library's location so Meson can find it?
I've seen find_library, but that's deprecated according the docs.
The dependency function is using pkg-config or cmake if pkg-config fails, to find external dependency (installed library).
When you install OpenCV4, please check if there is pkg-config for opencv4. Here is my command:
pkg-config --list-all | grep "opencv4"
and output:
opencv4 OpenCV - Open Source Computer Vision Library
Also, check PKG_CONFIG_PATH environment variable. pkg-config will use that path to search for .pc files.
Edit:
be sure to use -D OPENCV_GENERATE_PKGCONFIG=YES when building opencv with cmake.

How to setup ROS environment variable on Ubuntu 20.04?

I tried following this guide to install ROS, but even after adding ROS source.list and its key
sudo apt install ros-melodic-desktop-full
gave error.
E: Unable to locate package ros-melodic-desktop-full
Then I ran this command
sudo apt search ros
to see if any such package exists. I couldn't find ros-melodic-desktop-full but I found another similar package ros-desktop-full.
So I installed it instead. The installation went smooth without giving any errors.
Next step in the guide is to set-up ROS environment variable, but I have no such directory
/opt/ros
So how do I setup the environment variable?
P.S.
I also installed some tools and dependencies with this command
sudo apt install python3-rosdep python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
and initialized rosdep
sudo rosdep init
rosdep update
The ros-desktop-full package you installed is part of the official Ubuntu release.
ROS Melodic (and in the future, Noetic) is published by the OSRF in a separate repository (packages.ros.org). These packages install to /opt/ros/. However, some ROS packages have also been ported to Debian, which is how they found their way to Ubuntu (which derives from Debian).
The Debian packages are fully functional, but they do not install to /opt/ros. Instead, everything is integrated in the operating system itself. This means that you need to set up your personal workspace slightly differently.
Given that most tutorials assume that you use the OSRF packages, I suggest you either wait for the Noetic release (scheduled for the end of May 2020), then install ros-noetic-desktop-full, or downgrade to Ubuntu 18.04 LTS to use ROS Melodic.
From the documentation here, melodic is only supported on Ubuntu 18.04. The ROS version targeting Focal (20.04) is Noetic, but that one has not been released yet (see Distributions). I'm not sure what ROS version Ubuntu packages (the ros-desktop-full one you installed), but I was not successful in using it.
If you really do want to use Ubuntu 20.04, then I think your best option currently is to compile from source. Last time I checked the precompiled debs for Noetic are not yet available at http://packages.ros.org/ros/ubuntu (you can track release progress at github issue 21513). No idea if compiling Noetic from source is easy or hard, but I was able to compile ROS2 foxy from source without too much trouble though.

luarocks lyaml installation error

on luarocks install lyaml I get following error:
Error: Could not find expected file libyaml.a, or libyaml.so, or libyaml.so.* for YAML -- you may have to install YAML in your system and/or pass YAML_DIR or YAML_LIBDIR to the luarocks command. Example: luarocks install lyaml YAML_DIR=/usr/local
lua version: 5.1.5
How do I install YAML in system to start using lyaml rock?
Whenever you get a LuaRocks message saying you may have to install ____ in your system it means the rockspec has an external dependency.
Installing external dependencies
The way to satisfy this dependency is to install the package using the appropriate means of your system: if using Debian/Ubuntu, with apt-get, if using macOS, probably using Homebrew, etc.
Note that for building code, in systems that have the concept of dev packages, such as most Linux distributions, you need to install both the main library package and the dev package (which contains the header files for compilation). For example, for Debian/Ubuntu, to satisfy this dependency you need to run apt-get install libyaml libyaml-dev.
Unfortunately, the names are not fully consistent across systems and distros: a module may be called ncurses-dev in one system, libncurses6w-dev in another, etc. So in your particular case you'll have to search around for the right name of the YAML library (the package providing libyaml) in your system.
Once the external dependency is installed...
Installing a library with the system package manager will usually install the necessary files in locations that are automatically detected by LuaRocks, so running
luarocks install lyaml
again should find the libyaml files and proceed with the installation.
If external dependencies are installed in a non-standard location
If that fails, you can find the directories where the library (libyaml.so) and header (yaml.h) were installed and tell LuaRocks about it. For example, if libyaml.so was installed in some non-standard locations such as /opt/lib/yaml/libyaml.so and the header in /opt/include/yaml-1/yaml.h you would do this:
luarocks install lyaml YAML_LIBDIR=/opt/lib/yaml/ YAML_INCDIR=/opt/include/yaml-1/
This kind of situation happens when a system installs headers or libraries in a subdirectory. For example, for LuaSec on the Mac, which uses OpenSSL, it is sometimes necessary to use pathnames like this:
luarocks install luasec OPENSSL_INCDIR=/usr/local/opt/openssl/include OPENSSL_LIBDIR=/usr/local/opt/openssl/lib

How do install libraries for both Lua5.2 and 5.1 using Luarocks?

I am writing a small Lua project and using Luarocks to install my 3rd-party dependencies. The default Lua version on my machine is 5.2 and up to this point everything is working just fine.
However, today I have stumbled across a problem that is confusing me. I want to run my program on Lua 5.1 and Luajit to see if it would also work on those versions but I am having a hard time getting Luarocks to download the appropriate versions of the dependencies. As a last resort hack, I have tried to tell Lua5.1 to use the 5.2 libraries that Luarocks installed (by setting the LUA_PATH environment variable to the same value as LUA_PATH_5_2) but unfortunately that is not enough: my project depends on LuaFileSystem, a C-based module, so I'm going to need to have separate versions of it installed for 5.1 and 5.2.
What do I have to do to install both the 5.1 and 5.2 versions of my dependencies? Do I need to pass some parameters to theluarocks install command? Do I need to have multiple instances of Luarocks installed on my machine? One thing that confuses me is that the inside the .luarocks folder things are classified under a 5.2 subfolder (~/.luarocks/share/lua/5.2/), suggesting that maybe there could be a way to install things in a sibling 5.1 folder but at the same time there is only one bin folder, suggesting that luarocks is only able to handle one version of Lua at a time...
Based on your reference to ~/.luarocks/share/lua/5.2/, you seem to be running a Unix system (Linux or Mac). You can install the latest version of LuaRocks twice, for both Lua 5.1 and Lua 5.2 like this:
./configure --lua-version=5.1 --versioned-rocks-dir
make build
sudo make install
And then again for 5.2:
./configure --lua-version=5.2 --versioned-rocks-dir
make build
sudo make install
This will get you /usr/local/bin/luarocks-5.1 and /usr/local/bin/luarocks-5.2. If you installed Lua 5.1 and 5.2 in /usr/local/, and each of them will use its own ~/.luarocks/lib/luarocks/rocks-5.x/ entry for the user tree (and /usr/local/lib/luarocks/rocks-5.x for the system tree), and install modules to the right location at /usr/share/lua/5.x/ and ~/.luarocks/share/lua/5.x/ (and likewise for lib) appropriately.
As suggested by moteus, I decided to install a second version of Luarocks for Lua 5.1. But he is using Windows and I am using Linux so here is what I did:
Download the source for the latest version of Luarocks on the Luarocks website
From the source directory, run the ./configure script:
/configure --prefix="${HOME}/.luarocks51" --lua-suffix=5.1
The prefix setting tells Luarocks to put its stuff on the .luarocks51 folder, next to the existing .luarocks folder from my 5.2 install of Luarocks. The lua-suffix parameter tells Luarocks to use Lua 5.1 instead of the default lua version in my machine (5.2). This depends on me having named the interpreter for Lua 5.1 as lua5.1 (Debian installed mine on /usr/bin/lua5.1). Finally, Luarocks managed to automatically detect where the 5.1 headers and libraries are installed (/usr/include/lua5.1/) but if it didn't I guess I could have specified that with the --with-lua-include and --with-lua-lib parameters.
Compile Luarocks with make
Install it with make isntall (no need for Sudo since I'm installing it in a local directory).
Configure my 5.1 environment to use the libraries downloaded by Luarocks. I added the following to my .bashrc:
export PATH=$PATH:~/.luarocks/bin:~/.luarocks51/bin
export LUA_CPATH=";;${HOME}/.luarocks51/lib/lua/5.1/?.so"
export LUA_PATH=";;${HOME}/.luarocks51/share/lua/5.1/?.lua;${HOME}/.luarocks51/share/lua/5.1/?/init.lua"
export LUA_CPATH_5_2=";;${HOME}/.luarocks/lib/lua/5.2/?.so"
export LUA_PATH_5_2=";;${HOME}/.luarocks/share/lua/5.2/?.lua;${HOME}/.luarocks/share/lua/5.2/?/init.lua"
The 5.1 configuration also works for Luajit.
The executable for the 5.1 version of luarocks is named luarocks-5.1:
luarocks-5.1 install lfs
You have to mention both lua version and lua dir in the latest versions:
luarocks --lua-dir=$(brew --prefix)/opt/lua#5.1 --lua-version=5.1 install lua-cassandra
Using homebrew, you can do:
brew install lua51 # Lua 5.1
brew install lua # Lua latest
Luarocks comes with Lua, so you can do:
# Install Lua 5.1 version of any package
luarocks-5.1 install moonscript
# Install Lua latest version of any package
luarocks install moonscript

Resources