MSYS2 / MSYS / MinGW: Difference between revisions

From miki
Jump to navigation Jump to search
 
(26 intermediate revisions by the same user not shown)
Line 18: Line 18:
* [http://www.mingw.org/wiki/msys MSYS]
* [http://www.mingw.org/wiki/msys MSYS]
* [http://www.mingw.org/ MinGW]
* [http://www.mingw.org/ MinGW]

== Development ==
=== Install base packages ===
* Install base packages for development.
: This will install the GNU gcc toolchain, to build native Linux applications using the GNU C libraries.

pacman -S base base-devel gcc procps python3

=== Developing with MinGW ===
See [[MinGW dev]] page.

=== gcc vs MinGW-64 gcc===
MSYS2 comes with '''three''' flavors of gcc [https://stackoverflow.com/questions/49475006/what-is-different-between-gcc-exe-in-msys2-usr-bin-and-gcc-exe-in-msys2-mingww64?rq=1]:
* Standard gcc, installed in {{file|/usr/bin}}, and relying on {{file|msys-2.0.dll}}.
* MinGW gcc targetting 64-bit Windows application, installed in {{file|/mingw64/bin}}.
* MinGW gcc targetting 32-bit Windows application, installed in {{file|/mingw32/bin}}.

=== Using a different toolchain in a shell ===
By default, the selected toolchain depends on the shortcut used to launch MSYS2.

To change the toolchain from within the shell, defined <code>MSYSTEM</code> and source {{file|/etc/profile}}:

<source lang="bash">
export MSYSTEM=MINGW32; source /etc/profile # Target MSYS2-MinGW 32-bit
export MSYSTEM=MINGW64; source /etc/profile # Target MSYS2-MinGW 64-bit
export MSYSTEM=MSYS; source /etc/profile # Target MSYS2
</source>


== Tips ==
== Tips ==


=== Install package ===
=== Install / Query package ===


Use pacman:
Install using pacman:


<source lang="c">
<source lang="c">
pacman -S git
pacman -S git
</source>

Searching with pacman:

<source lang="c">
pacman -Ss ssh
</source>


Another alternative is '''pacboy''':

<source lang="bash">
pacboy find somepackage
</source>
</source>


Line 38: Line 78:
cd ~/offline_packages
cd ~/offline_packages
pacman -Syw base base-devel mingw-w64-x86_64-toolchain --cachedir .
pacman -Syw base base-devel mingw-w64-x86_64-toolchain --cachedir .
repo-add ./offline.db.tar.gz ./*
find -newer offline.db.tar.gz -name "*.xz" | xargs repo-add offline.db.tar.gz
</source>
</source>


Line 76: Line 116:


;Troubleshooting
;Troubleshooting
Above is the '''theory''', in practice, pacman sometimes does not find some packages, although they ''are'' there. Here some tips to solve those issues
Above is the '''theory''', in practice, pacman sometimes does not download all dependency packages, and these must be downloaded manually. In that case look at missing dependencies in the error message, and download these packages explicitly.
* Look at missing dependencies in the error message. Some packages may refuse to install because they depend on another package that is not available in the repository (for instance {{deb|libgdbm}}).


More information:
More information:
* https://wiki.archlinux.org/index.php/Offline_installation_of_packages
* https://wiki.archlinux.org/index.php/Offline_installation_of_packages

=== SSH and proxy ===
Use <code>connect-proxy</code> (compile from source). See [[Proxy]].

=== Install SSH server ===
* First install the MSYS2 package.
<source lang="bash">
pacman -S openssh
</source>
* Then create some keys (not sure these steps are necessary).
<source lang="bash">
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa
ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519
vi /etc/ssh/ssd_config
</source>
* If necessary, edit {{file|/etc/ssh/sshd_config}}.

In any case, when everything's done, just launch the server manually:

<source lang="bash">
/usr/bin/sshd
</source>


I guess this could be done automatically by adding something to Start Menu, but Windows being such a gigantic pile of sh*t, I'm sure this would fait in many different ways that I don't even want to explore.
Instead, I added the following to my {{file|~/.bashrc}}:

<source lang="bash">
pgrep sshd > /dev/null || echo "WARNING: sshd not running. Consider running '/usr/bin/sshd'"
</source>


Last step is of course to grant access to this machine. This is done by copying your user public key (let's assume it is called {{file|id_rsa.pub}}) to {{file|~/.ssh/authorized_keys}}. For instance:

<source lang="bash">
cat path/to/your/id_rsa.pub >> ~/.ssh/authorized_keys
</source>

=== autossh ===
{{note|Strangely I cannot connect to http://www.harding.motd.ca from my ISP, but it was reachable from e.g. OVH}}
Building autossh on msys2 is quite straightforward. Taking recipe from [https://www.everythingcli.org/ssh-tunnelling-for-fun-and-profit-autossh/ everythingcli.org]:
<source lang="bash">
# Install deps
pacman -S ssh gcc make tar
wget http://www.harding.motd.ca/autossh/autossh-1.4e.tgz
# Note: http://www.harding.motd.ca/autossh/autossh-1.4e.tgz is unreachable from my ISP, but was available from OVH server.
tar xvzf autossh-1.4e.tgz
cd autossh-1.4e
./configure
make
sudo make install
</source>

=== Install Git For Windows ===
The best option for git in MSYS2 is to install Git For Windows normally.

Then create the following file {{file|/etc/profile.d/git-for-windows.sh}}:
<source lang="bash">
echo 'export PATH="$PATH:/c/Program Files/git/mingw64/bin"' > /etc/profile.d/git-for-windows.sh
</source>

== Questions ==

=== Why three MSYS2 launchers? ===
On Windows, we have three launchers:
* MSYS2
:
* MSYS2 MinGW 64-bit
: <code>uname</code> returns <code>MINGW64_NT-10.0</code>.
* MSYS2 MinGW 32-bit
: <code>uname</code> returns <code>MINGW32_NT-10.0</code>.

Are there other differences?

Relevant links maybe: [https://github.com/msys2/msys2/wiki/MSYS2-introduction MSYS2 introduction], [https://github.com/msys2/msys2/wiki/How-does-MSYS2-differ-from-Cygwin difference with Cygwin].

== Troubleshooting ==

=== msys2 gcc error 1 ===
Starting make, we get the error:
make: *** [build] Error 1
The error is due to a conflicting {{file|msys-2.0.dll}} found in the path. Search for all similar DLL, and make sure none are lying around, except for the one in {{file|c:\msys64}}.

=== msys2 startup very slow ===
The fix is to remove <code>db</code> from file {{file|/etc/nsswitch.conf}}, and optionally create files {{file|/etc/passwd}} and {{file|/etc/group}}

<source lang="bash">
mkpasswd -l -c > /etc/passwd # Avoid username Unknown+User
mkgroup -l -c > /etc/group
sed -ri 's/^(passwd:).*/\1 files # db/; s/^(group:).*/\1 files # db/' /etc/nsswitch.conf
</source>

Source:
* https://github.com/msys2/MSYS2-packages/issues/138#issuecomment-70813762
* https://gist.github.com/k-takata/9b8d143f0f3fef5abdab

=== Ctrl-C breaks gdb ===
To avoid this to happen:

* Launch msys2 in a normal CMD console. For this add <code>-defterm</code> on the shortcut line,
* Do not launch gdb from within a Makefile. Otherwise make will intercept the Ctrl-C and exits.
* Do not launch gdb from within ssh.

More reading:
* [http://mingw.5.n7.nabble.com/gdb-and-Ctrl-C-td22922.html gdb and Ctrl-C]

=== No icon on msys2 window ===
Probably due to using <code>-defterm</code> on the shortcut.

Workaround:
* Add <code>-no-start</code> on the shortcut line, and
* Launch MSYS2 with Launchy.

=== pacman -Syuu very slow / reading terabytes ===
A simple <code>pacman -Syuu</code> is taking ages, and reading terabytes of information.

I filed a ticket on that somewhere. [https://github.com/msys2/MSYS2-packages/issues/1788 here].

World is sh*t.

=== SPAM: shared_info::initialize: size of shared memory region changed from ===
* This occured when upgrading gcc.
* Solution:
:* Exit MSYS2.
:* Kill '''all''' MSYS2 processes.
:* Relaunch MSYS2.
:* Repeat installation.

=== Prevent name mangling on MSYS2 ===
MSYS2 try to change paths in parameters when calling Windows executable.

To avoid this, define the variable <code>MSYS2_ARG_CONV_EXCL</code> [https://stackoverflow.com/questions/7250130/how-to-stop-mingw-and-msys-from-mangling-path-names-given-at-the-command-line]:
<source lang="bash">
MSYS2_ARG_CONV_EXCL="*" myexec /some/slash/param
</source>

Latest revision as of 16:52, 29 August 2021

This page is about:

  • MSYS, MSYS is a collection of GNU utilities such as bash, make, gawk and grep on Windows.
  • MinGW, "Minimalist GNU for Windows". MinGW is a minimalist development environment for native Microsoft Windows applications.
  • MSYS2, a Cygwin-derived software distro for Windows using Arch Linux's Pacman. MSYS2 is an independent rewrite of MSYS, based on modern Cygwin (POSIX compatibility layer) and MinGW-w64 with the aim of better interoperability with native Windows software.

MSYS and MinGW are mostly inactive now. MSYS2 is the active alternative.

References

MSYS2
  • Pacman rosetta, find the corresponding pacman command from those used in popular Linux distribution.
MSYS / MinGW

Development

Install base packages

  • Install base packages for development.
This will install the GNU gcc toolchain, to build native Linux applications using the GNU C libraries.
pacman -S base base-devel gcc procps python3

Developing with MinGW

See MinGW dev page.

gcc vs MinGW-64 gcc

MSYS2 comes with three flavors of gcc [1]:

  • Standard gcc, installed in /usr/bin, and relying on msys-2.0.dll.
  • MinGW gcc targetting 64-bit Windows application, installed in /mingw64/bin.
  • MinGW gcc targetting 32-bit Windows application, installed in /mingw32/bin.

Using a different toolchain in a shell

By default, the selected toolchain depends on the shortcut used to launch MSYS2.

To change the toolchain from within the shell, defined MSYSTEM and source /etc/profile:

export MSYSTEM=MINGW32; source /etc/profile    # Target MSYS2-MinGW 32-bit
export MSYSTEM=MINGW64; source /etc/profile    # Target MSYS2-MinGW 64-bit
export MSYSTEM=MSYS; source /etc/profile       # Target MSYS2

Tips

Install / Query package

Install using pacman:

pacman -S git

Searching with pacman:

pacman -Ss ssh


Another alternative is pacboy:

pacboy find somepackage

Install/update MSYS2 packages on offline computer

MSYS2 can be installed and updated on a computer that has no internet connection. It only requires a secondary computer with internet access. We follow the procedure on SO:

On the computer with internet access
mkdir ~/offline_packages
cd ~/offline_packages
pacman -Syw base base-devel mingw-w64-x86_64-toolchain --cachedir .
find -newer offline.db.tar.gz -name "*.xz" | xargs repo-add offline.db.tar.gz

Now copy offline_packages to an external storage device.

On offline computer
  • Install MSYS2.
  • Copy offline_packages to a path that MSYS2 can access (for instance C:/msys64/home/user/offline_packages)
  • Edit C:/msys64/etc/pacman.conf:
  • Comment out the [mingw32], [mingw64], [msys] repositories.
  • Add a new section (update as necessary):
[offline]
SigLevel = Optional
Server = file:///home/user/offline_packages
  • Then in an MSYS2 terminal:
pacman -Syu
pacman -S --needed base base-devel mingw-w64-x86_64-toolchain

Later on, we can update the database, either adding new package or replacing one with a newer version.

On computer with internet access
pacman -Syw liblz4 procps python3 --cachedir .
repo-add ./offline.db.tar.gz liblz4-1.8.2-1-x86_64* procps-3.2.8-2-x86_64* python-3.6.6-1-x86_64*
On offline computer

Update the repository with the newer files, and update the offline computer as usual.

cp -ruv offline_packages /home/user
pacman -Syu
pacman -S --needed procps python3
Troubleshooting

Above is the theory, in practice, pacman sometimes does not download all dependency packages, and these must be downloaded manually. In that case look at missing dependencies in the error message, and download these packages explicitly.

More information:

SSH and proxy

Use connect-proxy (compile from source). See Proxy.

Install SSH server

  • First install the MSYS2 package.
pacman -S openssh
  • Then create some keys (not sure these steps are necessary).
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
ssh-keygen -f /etc/ssh/ssh_host_ecdsa_key -N '' -t ecdsa
ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519
vi /etc/ssh/ssd_config
  • If necessary, edit /etc/ssh/sshd_config.

In any case, when everything's done, just launch the server manually:

/usr/bin/sshd


I guess this could be done automatically by adding something to Start Menu, but Windows being such a gigantic pile of sh*t, I'm sure this would fait in many different ways that I don't even want to explore. Instead, I added the following to my ~/.bashrc:

pgrep sshd > /dev/null || echo "WARNING: sshd not running. Consider running '/usr/bin/sshd'"


Last step is of course to grant access to this machine. This is done by copying your user public key (let's assume it is called id_rsa.pub) to ~/.ssh/authorized_keys. For instance:

cat path/to/your/id_rsa.pub >> ~/.ssh/authorized_keys

autossh

 ✐  Strangely I cannot connect to http://www.harding.motd.ca from my ISP, but it was reachable from e.g. OVH

Building autossh on msys2 is quite straightforward. Taking recipe from everythingcli.org:

# Install deps
pacman -S ssh gcc make tar
wget http://www.harding.motd.ca/autossh/autossh-1.4e.tgz
# Note: http://www.harding.motd.ca/autossh/autossh-1.4e.tgz is unreachable from my ISP, but was available from OVH server.
tar xvzf autossh-1.4e.tgz
cd autossh-1.4e
./configure
make
sudo make install

Install Git For Windows

The best option for git in MSYS2 is to install Git For Windows normally.

Then create the following file /etc/profile.d/git-for-windows.sh:

echo 'export PATH="$PATH:/c/Program Files/git/mingw64/bin"' > /etc/profile.d/git-for-windows.sh

Questions

Why three MSYS2 launchers?

On Windows, we have three launchers:

  • MSYS2
  • MSYS2 MinGW 64-bit
uname returns MINGW64_NT-10.0.
  • MSYS2 MinGW 32-bit
uname returns MINGW32_NT-10.0.

Are there other differences?

Relevant links maybe: MSYS2 introduction, difference with Cygwin.

Troubleshooting

msys2 gcc error 1

Starting make, we get the error:

make: *** [build] Error 1

The error is due to a conflicting msys-2.0.dll found in the path. Search for all similar DLL, and make sure none are lying around, except for the one in c:\msys64.

msys2 startup very slow

The fix is to remove db from file /etc/nsswitch.conf, and optionally create files /etc/passwd and /etc/group

mkpasswd -l -c > /etc/passwd    # Avoid username Unknown+User
mkgroup -l -c > /etc/group
sed -ri 's/^(passwd:).*/\1 files # db/; s/^(group:).*/\1 files # db/' /etc/nsswitch.conf

Source:

Ctrl-C breaks gdb

To avoid this to happen:

  • Launch msys2 in a normal CMD console. For this add -defterm on the shortcut line,
  • Do not launch gdb from within a Makefile. Otherwise make will intercept the Ctrl-C and exits.
  • Do not launch gdb from within ssh.

More reading:

No icon on msys2 window

Probably due to using -defterm on the shortcut.

Workaround:

  • Add -no-start on the shortcut line, and
  • Launch MSYS2 with Launchy.

pacman -Syuu very slow / reading terabytes

A simple pacman -Syuu is taking ages, and reading terabytes of information.

I filed a ticket on that somewhere. here.

World is sh*t.

SPAM: shared_info::initialize: size of shared memory region changed from

  • This occured when upgrading gcc.
  • Solution:
  • Exit MSYS2.
  • Kill all MSYS2 processes.
  • Relaunch MSYS2.
  • Repeat installation.

Prevent name mangling on MSYS2

MSYS2 try to change paths in parameters when calling Windows executable.

To avoid this, define the variable MSYS2_ARG_CONV_EXCL [2]:

MSYS2_ARG_CONV_EXCL="*" myexec /some/slash/param