Invoke MSYS2 Shell from Command Prompt or PowerShell - shell

Starting from Command Prompt or PowerShell (either is fine; I can figure out how to do the other given one), how can I invoke the MSYS2 shell to run a command?
More specific issue
I'm including this information to avoid an XY problem, but I strongly believe this is best solved by the answer to the above (more general) question.
In particular, I'm hoping to write a shell script to update the packages listed in Part III, Step 3 here. So I need something like:
[invoke msys2 bash] -c "pacman -Sy --needed msys2-runtime"
Calling the bash executable directly doesn't work:
C:\>C:\msys64\usr\bin\bash.exe -c "pacman -Sy --needed msys2-runtime"
/usr/bin/bash: pacman: command not found
I assume it's an environment problem. Changing PATH to include the path to MSYS2's bin directory doesn't fix the problem either. When it tries to install a package, bad things happens (nano is just an example):
C:\>bash -c "pacman -Sy --needed --noconfirm nano"
:: Synchronizing package databases...
mingw32 is up to date
mingw64 is up to date
msys is up to date
resolving dependencies...
looking for conflicting packages...
Packages (1) nano-2.3.6-2
Total Installed Size: 1.81 MiB
Net Upgrade Size: 0.17 MiB
:: Proceed with installation? [Y/n]
(1/1) checking keys in keyring [########################################################] 100%
(1/1) checking package integrity [########################################################] 100%
(1/1) loading package files [########################################################] 100%
(1/1) checking for file conflicts [########################################################] 100%
(1/1) checking available disk space [########################################################] 100%
(1/1) upgrading nano [########################################################] 100%
error: command (/usr/bin/bash /usr/bin/bash -c . /tmp/alpm_shqjUE/.INSTALL; post_upgrade 2.3.6-2 2.3.2-1 ) failed to execute correctly
Trying to invoke the batch file (C:\msys64\msys2_shell.bat) opens a new shell in a new window, which leaves me not knowing whether it failed or succeeded.
So how can I get the shell into MSYS2's normal state?

We're working hard to fix our messy update procedure, we want it to be trouble-free.
You can see some examples of how we invoke MSYS2 from a batch file when we create a new installer in:
https://github.com/Alexpux/MSYS2-packages/blob/master/msys2-installer/make-msys2-installer.bat
But as #StevenPenny suggests,
bash -l -c "pacman ..."
is the correct way.

Related

Can't install cargo-binutils library: Failed to find tool. Is `gcc.exe` installed?

When I run cargo install cargo-binutils, I get the below error. I have gcc installed and in my path, to the point where where gcc correctly returns the location.
gcc version: gcc.exe (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0
I couldn't find a solution to work, including the explanation in the link listed in the error. I'm on Windows 10.
error: failed to run custom build command for \`backtrace-sys v0.1.37`
Caused by:
process didn't exit successfully: \`C:\Users\blahblah\AppData\Local\Temp\cargo-installEvEWRS\release\build\backtrace-sys-075604757ab74d2a\build-script-build` (exit code: 1)
--- stdout
cargo:rustc-cfg=rbt
TARGET = Some("x86_64-pc-windows-gnu")
OPT_LEVEL = Some("3")
HOST = Some("x86_64-pc-windows-gnu")
CC_x86_64-pc-windows-gnu = None
CC_x86_64_pc_windows_gnu = None
HOST_CC = None
CC = None
CFLAGS_x86_64-pc-windows-gnu = None
CFLAGS_x86_64_pc_windows_gnu = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
running: "gcc.exe" "-O3" "-ffunction-sections" "-fdata-sections" "-m64" "-I" "src/libbacktrace" "-I" "C:\\Users\\BRENDA~1.BUR\\AppData\\Local\\Temp\\cargo-installEvEWRS\\release\\build\\backtra
ce-sys-1e77a4d4c3ba2eda\\out" "-fvisibility=hidden" "-DBACKTRACE_SUPPORTED=1" "-DBACKTRACE_USES_MALLOC=1" "-DBACKTRACE_SUPPORTS_THREADS=0" "-DBACKTRACE_SUPPORTS_DATA=0" "-DHAVE_DL_ITERATE_PHDR=
1" "-D_GNU_SOURCE=1" "-D_LARGE_FILES=1" "-Dbacktrace_full=__rbt_backtrace_full" "-Dbacktrace_dwarf_add=__rbt_backtrace_dwarf_add" "-Dbacktrace_initialize=__rbt_backtrace_initialize" "-Dbacktrac
e_pcinfo=__rbt_backtrace_pcinfo" "-Dbacktrace_syminfo=__rbt_backtrace_syminfo" "-Dbacktrace_get_view=__rbt_backtrace_get_view" "-Dbacktrace_release_view=__rbt_backtrace_release_view" "-Dbacktra
ce_alloc=__rbt_backtrace_alloc" "-Dbacktrace_free=__rbt_backtrace_free" "-Dbacktrace_vector_finish=__rbt_backtrace_vector_finish" "-Dbacktrace_vector_grow=__rbt_backtrace_vector_grow" "-Dbacktr
ace_vector_release=__rbt_backtrace_vector_release" "-Dbacktrace_close=__rbt_backtrace_close" "-Dbacktrace_open=__rbt_backtrace_open" "-Dbacktrace_print=__rbt_backtrace_print" "-Dbacktrace_simpl
e=__rbt_backtrace_simple" "-Dbacktrace_qsort=__rbt_backtrace_qsort" "-Dbacktrace_create_state=__rbt_backtrace_create_state" "-Dbacktrace_uncompress_zdebug=__rbt_backtrace_uncompress_zdebug" "-D
macho_get_view=__rbt_macho_get_view" "-Dmacho_symbol_type_relevant=__rbt_macho_symbol_type_relevant" "-Dmacho_get_commands=__rbt_macho_get_commands" "-Dmacho_try_dsym=__rbt_macho_try_dsym" "-Dm
acho_try_dwarf=__rbt_macho_try_dwarf" "-Dmacho_get_addr_range=__rbt_macho_get_addr_range" "-Dmacho_get_uuid=__rbt_macho_get_uuid" "-Dmacho_add=__rbt_macho_add" "-Dmacho_add_symtab=__rbt_macho_a
dd_symtab" "-Dmacho_file_to_host_u64=__rbt_macho_file_to_host_u64" "-Dmacho_file_to_host_u32=__rbt_macho_file_to_host_u32" "-Dmacho_file_to_host_u16=__rbt_macho_file_to_host_u16" "-o" "C:\\User
s\\BRENDA~1.BUR\\AppData\\Local\\Temp\\cargo-installEvEWRS\\release\\build\\backtrace-sys-1e77a4d4c3ba2eda\\out\\src/libbacktrace/alloc.o" "-c" "src/libbacktrace/alloc.c"
--- stderr
error occurred: Failed to find tool. Is `gcc.exe` installed? (see https://github.com/alexcrichton/cc-rs#compile-time-requirements for help)
https://github.com/alexcrichton/cc-rs#compile-time-requirements says:
Windows platforms targeting MinGW (e.g. your target triple ends in -gnu)
require cc to be available in PATH. We recommend the
MinGW-w64 distribution, which is using the
Win-builds installation system.
You may also acquire it via
MSYS2, as explained [here][msys2-help]. Make sure
to install the appropriate architecture corresponding to your installation of
rustc. GCC from older MinGW project is compatible
only with 32-bit rust compiler.
Try creating a symlink or hardlink to GCC called cc, somewhere on your path.
This happened to me as well. In my case I got:
failed to run custom build command for zstd-sys v2.0.1+zstd.1.5.2
Caused by: process didn't exit successfully:
C:\Users\asili\Documents\Programming\zero2prod\target\debug\build\zstd-sys-f37cc8bfd3eec6ac\build-script-build
(exit code: 1)
error occurred: Failed to find tool. Is gcc.exe installed? (see
https://github.com/alexcrichton/cc-rs#compile-time-requirements for
help)
I was able to solve it by following the steps on installing the Visual C++ extension from the VS Code marketplace.
This is how I did it:
Go to MSYS2.org https://www.msys2.org/ (You will also see the installation steps on the site, in case this answer gets outdated).
Download and install msys2-x86_64-20220603.exe (or whichever version is current). The installation is pretty straightforward, just take a note on the installation path as you will need to add this to the environment PATH later on.
A new program called "MSYS2" should've been installed. Open it, and you'll see a terminal window in it. You will run ALL of the commands mentioned below in this terminal. If you close it, open it again.
Run:
pacman -Syu
This will update the packages and databases.
Run (Again - This step may not be needed, but is recommended by MSYS2 in case packages need an additional updates.)
pacman -Syu
Run:
pacman -S --needed base-devel mingw-w64-x86_64-toolchain
You will now see a selection of all the packages. If you don't know which to choose, just press enter on your keyboard and you shall get all of them (that's what I ended up doing).
After that, gcc.exe will be installed the bin folder of mingw64. Therefore:
Add theC:\msys64\mingw64\bin file path to your path environment variable (or Wherever you decided to install it).
In case you need assistance on adding to the path, check out this link.
Remember to restart your CMD/Windows Terminal/Power Shell for the environment path to take place.

How do I execute autoconf on Windows as installed with Cygwin?

I'm trying to build a Linux-developed C++ project on a Windows 7 machine, and I figured that Cygwin would be one of the easiest ways to run the necessary build and compilation scripts (in my case, autoconf, make, and g++). I'm starting to run into problems, and I'd appreciate it if someone could showing me if I'm installing or doing something incorrectly.
I can install Cygwin with Chocolatey with the command
choco install -y cygwin
which places Cygwin in the C:\tools\cygwin directory. For convenience, I add C:\tools\cygwin\bin to my PATH.
Next I install the necessary packages in quiet mode with
C:\tools\cygwin\cygwin_setup.exe -q -P autoconf,make,gcc-g++
If I enter the command make, then that program runs and gives me the expected error message. But if I enter autoconf, then I get the following error:
'autoconf' is not recognized as an internal or external command, operable program or batch file.
I assume the reason is because, unlike most of the scripts in Cygwin's bin directory (such as make), this one is not a .exe file. When check the contents of autoconf in a text editor, I see just a single garbled line:
㰡祳汭湩㹫/usr/share/autotools/ac-wrapper.sh
The initial characters seem pretty suspect, but my guess is that the script is supposed to call the C:\tools\cygwin\usr\share\autotools\ac-wrapper.sh script.
So I tried to run that script as an executable with
C:\tools\cygwin\usr\share\autotools\ac-wrapper.sh
The first time I did this, it successfully generated the configure executable. I thought I had everything solved. But after I cleaned up the autoconf outputs and tried again, nothing happened. Even if I close the shell window and try again, a window briefly appears with a message and disappears, but nothing else happens.
I can see the message if I run the wrapper script with
sh C:\tools\cygwin\usr\share\autotools\ac-wrapper.sh
The message turns out to be the following error:
ac-wrapper: Unable to locate any usuable version of autoconf.
I tried these versions: 2.69:2.5 2.68:2.5 9999:2.5 2.99:2.5 2.98:2.5 2.97:2.5 2.96:2.5 2.95:2.5 2.94:2.5 2.93:2.5 2.92:2.5 2.91:2.5 2.90:2.5 2.89:2.5 2.88:2.5 2.87:2.5 2.86:2.5 2.85:2.5 2.84:2.5 2.83:2.5 2.82:2.5 2.81:2.5 2.80:2.5 2.79:2.5 2.78:2.5 2.77:2.5 2.76:2.5 2.75:2.5 2.74:2.5 2.73:2.5 2.72:2.5 2.71:2.5 2.70:2.5 2.69:2.5 2.68:2.5 2.67:2.5 2.66:2.5 2.65:2.5 2.64:2.5 2.63:2.5 2.62:2.5 2.61:2.5 2.60:2.5 2.59:2.5 2.5x:2.5 2.13:2.1
C:\tools\cygwin\usr\share\autotools\ac-wrapper.sh: line 19: printf: missing unicode digit for \u
With a base name of 'C: ools\cygwin\usr\shareutotoolsc-wrapper.sh'.
I assume that last Unicode-related error is due to the CJK characters in the autoconf file, but the issue with finding a usable version of autoconf is more concerning. What's going on here? Shouldn't I be able to run autoconf from the Windows command-line with Cygwin installed?
Most of the cygwin programs are implemented as special link, that works only
from a cygwin shell (like bash):
$ cd /usr/bin
$ ls -l autoconf
lrwxrwxrwx 1 Marco Kein 34 Oct 15 2018 autoconf -> /usr/share/autotools/ac-wrapper.sh
$ autoconf --version
autoconf (GNU Autoconf) 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+/Autoconf: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David J. MacKenzie and Akim Demaille.
These links for not-cygwin programs are normal files and they can not use them
D:\cygwin32T\bin>dir /a:s autoconf.*
Datenträger in Laufwerk D: ist DATA
Volumeseriennummer: D603-FB6E
Verzeichnis von D:\cygwin32T\bin
15.10.2018 08:53 82 autoconf
1 Datei(en), 82 Bytes
0 Verzeichnis(se), 662.133.735.424 Bytes frei
The best way to use cygwin effectively is to run the provided Cygwin Terminal (aka Mintty) that will start a cygwin shell. Running Cygwin programs from windows CMD could cause unexpected results.

updating to svn 1.9.4 via command line in mac

I am using SVN against my will. The current team I work with uses it for version control and they are not always available to help me. I am just trying to go from SVN Version 1.8.13 to the latest 1.9.4
I have download it and I have ran this command too
curl -o subversion-latest.tar.gz http://apache.mirrors.tds.net/subversion/subversion-1.9.4.tar.gz
tar -xvf subversion-latest.tar.gz
I have combined these two different tutorials with no luck.
svn update version
stackover flow issue
I am STUCK at with the configure part..
mymac ~/Downloads/subversion-1.9.4/serf
$ ./configure
-bash: ./configure: No such file or directory
mymac ~/Downloads/subversion-1.9.4/serf
UPDATE
I exited out of serf path and on
`mymac ~/Downloads/subversion-1.9.4` file path i ran the `./configure` My command line ran a bunch of "checks"
configure: Configuring Subversion 1.9.4
configure: creating config.nice checking for gcc...
gcc checking whether the C compiler works...
yes but eventually shot an error at the end...
configure: error: failed to recognize APR_INT64_T_FMT on this platform
mymac ~/Downloads/subversion-1.9.4
I have the latest version of XCode..
UPDATE2 tried neon, again
mymac ~/Downloads/subversion-1.9.4
$ sh get-deps.sh neon
Local directory 'serf' already exists; the downloaded copy won't be used
Local directory 'apr' already exists; the downloaded copy won't be used
Local directory 'apr-util' already exists; the downloaded copy won't be used
get-deps.sh: line 151: get_neon: command not found
Usage: get-deps.sh
Usage: get-deps.sh [ apr | serf | zlib | sqlite | gmock ] ...
mymac ~/Downloads/subversion-1.9.4
$ cd neon
-bash: cd: neon: No such file or directory
UPDATE 3
ran this command first ..
mymac ~/Downloads/subversion-1.9.4
$ ./configure --prefix=/usr/local --with-serf=/usr/local/serf
configure: Configuring Subversion 1.9.4
configure: creating config.nice
checking for gcc... gcc
checking whether the C compiler works... yes
I guess I should install a new version of serf?
checking was serf enabled... no
An appropriate version of serf could not be found, so libsvn_ra_serf
will not be built. If you want to build libsvn_ra_serf, please
install serf 1.3.4 or newer.
configure: error: Serf was explicitly enabled but an appropriate version was not found.
I have no clue where to go from here and how to get around it. I already figure out that neon is no longer supported and I am using serf Can someone offer a different way to go about this? Please? Thanks!
Consider using Brew or MacPorts, if possible. Then this can be as simple as:
brew install svn
If you really must install from source,
it might not be as complicated as the steps you described so far.
Try these much simpler steps exactly:
cd /tmp
curl -o subversion-latest.tar.gz http://apache.mirrors.tds.net/subversion/subversion-1.9.4.tar.gz
tar -xvf subversion-latest.tar.gz
cd subversion-1.9.4
./configure --prefix=/tmp/local
make
make install
This will (hopefully) build Subversion and install it into /tmp/local. Test with this command:
/tmp/local/bin/svn --version
If the output looks good, then repeat from the start, but use a different value for --prefix, as appropriate in your environment.
(I tried, and this worked well for me, right now, btw.)
Maybe it's not so simple. In that case please update your question with the output where you get stuck.

gendef returning invalid syntax error

I am trying to install Theano for machine learning on my Windows 7 computer.
One of the last steps in installing the dependencies is to 'create a link library for GCC' by 'Opening up the Python shell and cd to C:\SciSoft. Then execute:
gendef WinPython-64bit-2.7.9.4\python-2.7.9.amd64\python27.dll
dlltool --dllname python27.dll --def python27.def --output-lib WinPython-
64bit-2.7.9.4\python-2.7.9.amd64\libs\libpython27.a
I've tried doing this but I get a invalid syntax error highlighted on 'WinPython'. I tried changing directory to go deeper and running gendef again and it also returned the same error. This is a copy and paste job from http://deeplearning.net/software/theano/install_windows.html#install-windows
I also followed the tutorial at the link to install Theano.
The line "Finally we need to create a link library for GCC. Open up the Python shell and cd to c:\SciSoft" is probably an error; "the Python shell" should be modified to "cmd.exe".
The two-line scripts are not python scripts, and can be successfully run on cmd.exe after changing directory to c:\SciSoft.

Trouble compiling mono from source via cygwin on windows

I work off my i: drive
I've downloaded the following mono source file mono-2.11.2.tar.bz2
I've installed the windows version of mono v2.11.2 to "I:\Mono-2.11.2"
I installed cygwin as per the following instructions found on the following webpage http://shana.worldofcoding.com/en/mono_cygwin_tutorial.html
I replaced the "make.exe" with the one from the mono website as per instruction. I had to get one more file "cygintl-2.dll" which resides in cygwin package libintl2/libintl2-0.12.1-3
I added the following my .bashrc file. I had to change "c/Mono-2.11.2/bin" to "i/Mono-2.11.2/bin"
PATH=.:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/cygdrive/i/Mono-2.11.2/bin
PKG_CONFIG_PATH=.:/lib/pkgconfig:/cygdrive/i/Mono-2.11.2/lib/pkgconfig
LD_LIBRARY_PATH=.:/usr/local/lib:/usr/lib:/lib:/cygdrive/i/Mono-2.11.2/lib
export PATH PKG_CONFIG_PATH LD_LIBRARY_PATH
I placed my mono source under the folder specified: /usr/src/mono/
So my dirs looks like:
i:
i:\cygwin\
i:\cygwin\usr\src\mono
i:\cygwin\usr\src\mono\mono
i:\cygwin\usr\src\mono\mcs etc etc
i:\Mono-2.11.2\bin etc
Now the instructions says I must change dirs to /usr/src/mono/mono and run "./autogen.sh --prefix=/usr/local" from the cygwin terminal
However that doesnt work. Running the above command from /usr/src/mono/ works fine.
Now heres the problem. The next instruction is to run "make". However this comes up with :
$ make
make: *** No targets specified and no makefile found. Stop.
I even tried running it from the /usr/src/mono/mono dir. Still no luck.
Can someone please suggest what I should do to be able to build the mono source on windows 7?
Update:
I needed to install the **gnu c++ compiler (g++)**. I just ran the cygwin setup again, searched for g++ and installed that. The autogen.sh ran to completion
The last lines of ./autogen.sh --prefix=/usr/local output should
look like bellow with Now type make to compile at the end. And it
generats Makefile in the same directory.
I think in your case ./autogen.sh failed. You can keep a log file
and check what it is complaining about.
./autogen.sh --prefix=/usr/local 2>&1 | tee autogen.log
More info: http://en.wikipedia.org/wiki/GNU_build_system
The end of the ./autogen.sh ouptut:
config.status: executing quiet-libtool commands
config.status: executing default commands
mcs source: mcs
olive source:
Engine:
GC: sgen and bundled Boehm GC with typed GC and parallel mark
TLS: __thread
SIGALTSTACK: yes
Engine: Building and using the JIT
oprofile: no
BigArrays: no
DTrace: no
LLVM Back End: no (dynamically loaded: no)
Libraries:
Moon Profile: no (boehm)
MonoDroid: no
MonoTouch: no
Mobile: no
JNI support: IKVM Native
libgdiplus: assumed to be installed
zlib: system zlib
Now type `make' to compile

Resources