Install Anaconda Python in Windows PowerShell

On Windows, Miniconda can be installed from the Command Prompt or PowerShell:

winget install --id=Anaconda.Miniconda3 -e

Update conda from Command Prompt / Terminal:

conda update conda

Setup the new shell support (PowerShell, Bash, Command Prompt, etc.) with

conda init

Reopen Terminal to see new conda environment.


If message upon opening PowerShell like:

Documents\WindowsPowerShell\profile.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170

Consider ExecutionPolicy like:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

CTest WILL_FAIL segfault SIGABRT catch

By design, CTest WILL_FAIL test property does not handle segmentation faults and other unexpected terminations. That is, a failing test will also show as failed in CTest, when the desire may have been to show an intended failure as success via WILL_FAIL. A simple workaround for this is to make a wrapper call for the intentionally segfaulting executable and catch that result, as in example project.

CMake ignore Anaconda libraries

Anaconda Python conda activate puts Conda directories first on environment variable PATH. This leads CMake to prefer to find Anaconda binaries (find_library, find_program, …) over later directories on PATH. Anaconda libraries are generally incompatible with the system or desired compiler. For certain libraries like HDF5, Anaconda is particularly problematic at interfering with CMake.

Fix by putting in CMakeLists.txt like the following. CMAKE_IGNORE_PREFIX_PATH does not take effect if set within Find*.cmake.

# exclude Anaconda directories from search
if(DEFINED ENV{CONDA_PREFIX})
  list(APPEND CMAKE_IGNORE_PREFIX_PATH $ENV{CONDA_PREFIX})
  list(APPEND CMAKE_IGNORE_PATH $ENV{CONDA_PREFIX}/bin)
  # need CMAKE_IGNORE_PATH for CMake < 3.23
  # and to ensure system env var PATH doesn't interfere
  # despite CMAKE_IGNORE_PREFIX_PATH
endif()

To totally omit environment variable PATH from CMake find_* use CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH:

set(CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH false)

However, this can be too aggressive i.e. it might miss other programs on PATH actually wanted.

Folder comparison with vscode

While Meld is a popular tool to compare folders, Visual Studio Code “vscode” can compare folders as well via vscode extension Compare Folders. In Unix-like shells, an alias can be used to ease command line use:

alias vsdiff="COMPARE_FOLDERS=DIFF code"

Then, to compare two folders, use:

vsdiff folder1 folder2

Git submodule change remote

Git submodules can switch remotes. This is useful when making a pull request for a project that relies on another pull request submodule. Verify the change in the top project’s “.gitmodules” file.

Example: suppose the directory “subdir” is a Git submodule. In this command, do not put “./subdir” or “subdir/”, just “subdir” by itself. Suppose you also wish to change the branch to “feat1” in the submodule.

git submodule set-url -- subdir https://github.invalid/username/new

git submodule sync

git -C subdir pull

git -C subdir switch feat1

Xcode new linker workaround

Whether using Clang/LLVM or Homebrew GNU compiler, GNU ld is not supported on macOS, only the Apple macOS Xcode ld is supported. The new ld linker in Xcode 15 breaks numerous projects, including OpenMPI < 4.1.6. The workaround is to use the classic linker, which is still supported in Xcode 15.

Set in ~/.zshrc

export LDFLAGS="$LDFLAGS -Wl,-ld_classic"

or specify on the program command line like:

LDFLAGS="$LDFLAGS -Wl,-ld_classic" make

Note that for CMake, LDFLAGS environment variable is read only on the first CMake configure and cached.

Run Bash scripts from Windows

For certain use cases, it’s feasible to run a Bash script from within Windows using Windows Subsystem for Linux (WSL). Another way to run Bash scripts from within Windows itself without WSL is the Bash shell installed with Git on Windows.

Start the Bash script you want to run from Linux or Windows with the shebang (first line of Bash script file):

#!/bin/bash; C:/Program\ Files/Git/git-bash.exe

This tells the shell (Linux or Windows) to first try /bin/bash which is a Unix-like path, and then try the Git Bash shell on Windows. If Python is on Windows Path, one can use Bash scripts that invoke Python scripts.

CMake override default compiler flags

CMake outputs default compiler flags based on platform and project configuration, which can be overridden. This example shows how to override the default compiler flags by putting the user flags later in the command line