Scientific Computing

GDB debugger for macOS Apple Silicon

GDB debugger is not yet readily available for macOS with Apple Silicon CPU. GDB is installable on Apple Silicon Macs via Homebrew, but it is not functional on Apple Silicon Macs for local executables.

It has long been possible to use a virtual machine with Linux for ARM64 to run GDB within the VM. When trying to use GDB on Apple Silicon for local executables, it doesn’t work:

gdb ./myexe
r

Don’t know how to run. Try “help target”.

To use GDB on an Apple Silicon Mac for local executables, it seems a Linux VM is the best option.

Mathworks / Matlab ransomware May 2025

The Mathworks experienced a major outage starting on May 18, 2025 due to a ransomware attack. The Mathworks’ license servers have been effectively required by default for Matlab for ~ five years. Virtually all Mathworks services were down initially for about a week, and then services are gradually being restored. The outage affects users worldwide regarding ability to start Matlab or install toolboxes. Trying to access Mathworks services results in a 503 return code or “no healthy upstream” or similar. Previously, external institutions cited a cyberattack.

Internet discussions have been peppered with recommendations to switch to GNU Octave, which is a free and open-source alternative to Matlab. However, the proprietary toolboxes that add so much value and functionality to Matlab are often not available for GNU Octave. Examine the GNU Octave Help forum to assess issues facing Octave users vs. Matlab Answers forum. It behooves instructors to consider avoiding proprietary toolboxes except where essential to the learning goals. Note that Python packages (and libraries in just about every programming language) have also experienced cyberattacks. Matlab adds serious value to many research and development projects, but the reliance on a single vendor for such a critical tool is a risk that should be considered.

Transitioning to open-source alternatives like GNU Octave or Python take considerable effort. Using the Matlab Engine for Python can help incrementally transition Matlab projects to Python.

Computer audio connections for ham radio

Apple has adaptive impedance for the TRRS connector on MacBook. Windows Logo certified computers likewise have standards for voltage levels and impedance for audio input and output. Instead of the built-in computer audio interface, we generally recommend using an external USB sound card to reduce risk of damage to the computer in case of voltage surges. Consider two 3.5mm TRS cables (one each for input and output) to the radio connector (typically the microphone connector that also has fixed level audio output) and a USB sound card. The USB sound card can be used on different computers once it’s known to work with the radio audio interface. At a minimum, a grounded coaxial surge protector should be used in the antenna feedline along with a fused, surge-protected power supply. Consider using an older laptop that still runs a currently supported operating system as a dedicated radio computer. This avoids risking an expensive laptop when an older laptop is often more than adequate for digital ham radio modes.

Monitor website status with curl

When a desired website is down or a new website is about to become available, one can use the “curl” program to check the status of the website HTTP response code. Using a periodic check with watch program one can monitor the status for an extended period of time. Keep in mind that the website might have anti-DOS measures that block repeated requests from the same IP address. Set “watch” interval and maximum number of requests to avoid being blocked.

Use a command like the following to check every 60 seconds for up to 60 times (1 hour):

watch -n 60 -q 60 curl -s -w %{response_code} -o /dev/null URL

Curl command reference:

curl -s -w %{response_code} -o /dev/null URL
-o /dev/null
discard the webpage content to avoid screen clutter. On Windows, use -o NUL instead.
-s
silent mode
-w %{response_code}
write the HTTP response code to console
URL
the desired URL to check

C++ attribute specifiers

C++ attribute specifiers add metadata to declarations and definitions. The metadata can be used by the compiler and by the developer to help understand the code intent.

Commonly used C++17 attributes such as [[maybe_unused]] and [[fallthrough]] suppress compiler warnings and signal developer intent for clarity.

C++20 attributes such as [[likely]] and [[unlikely]] may be used by the compiler to optimize compilation, and also provide human code readers insight into the intent of the algorithm.

GCC ≥ 5 feature test macro __has_cpp_attribute() checks if an attribute is supported by the compiler–even if the command line specified standard is older.

maybe_unused attribute

To enable code to fallback to no attribute with older compilers, use [[maybe_unused]] attribute in declaration AND in the definition to be compatible with GCC:

int windows_fun(int x, [[maybe_unused]] int y) {

#ifdef _WIN32
  return y;
#else
  return x;
#endif
}

On non-Windows systems, the compiler would have issued a warning about y being an unused argument. The [[maybe_unused]] attribute suppresses that warning.

fallthrough attribute

The [[fallthrough]] attribute is used to indicate that a fall-through in a switch statement is intentional. This attribute can be used to suppress warnings about missing break statements in a switch block.

In the header file:

#ifndef __has_cpp_attribute
#define __has_cpp_attribute(x) 0
#endif

#if __has_cpp_attribute(likely)
#define LIKELY [[likely]]
#else
#define LIKELY
#endif

switch (x) {
  case 1:
    x++;
    [[fallthrough]];
  case 2:  LIKELY
    x--;
}

cmake_path(GET in PARENT_PATH out) trailing slash

When using cmake_path(GET in PARENT_PATH out) to manipulate paths in CMake, be cautious about trailing slashes. The usual intent is to get the parent directory of a given path. If the trailing slash is not stripped, the same directory is returned, which may be unexpected.

Strip the trailing slash first like:

set(p "/path/to/directory/")

# Strip trailing slash
string(REGEX REPLACE "[\\/]+$" "" p "${p}")

cmake_path(GET p FILENAME n)

GitHub Oauth private repo access

To give secure access to private GitHub repositories on less-trusted systems like CI or HPC or shared workstation, consider GitHub Oauth tokens. The Oauth token can give read-only (or other fine-grained permissions) to all or a specific subset of repositories the GitHub account has access to.

Create a GitHub Oauth token with the desired permissions.

For read-only private GitHub repo access the “repo” permission group is selected.

Copy the text string token and SSH into the remote system where access is desired. Configure the global user Git config to use the Oauth token for the desired GitHub organization or user.

Private GitHub repo of a collaborator

Suppose a coworker with GitHub username “my1friend” has a private GitHub repo “myrepo”. Have “my1friend” add your GitHub username as a collaborator in the “myrepo” settings. Create a GitHub Oauth classic token with the “repo” permission group. Copy and paste that token string into the laptop or workstation you’ll use to access the private repo like:

git config --global url.https://oauth2:OauthToken@github.com/my1friend/.insteadOf https://github.com/my1friend/

A similar syntax is used for GitHub organizations or specific repositories.

The text OauthToken is replaced with the actual Oauth token string copied from GitHub.

Troubleshooting

Use git remote -v in the Git repo or Git submodule to ensure old information in ~/.gitconfig is not overriding the new API token. If a Git submodule won’t clone due to incorrect token credentials, try Git cloning the submodule repository itself in another directory to see if the old credential are slipping in somewhere.


Related: Git pull HTTPS push SSH

CMake per-language option flags

CMake can set per-language compiler flags scoped to directory or target. The directory scope propagates to targets in the directory and subdirectories. Per-language options that are intended for all targets in the project are often set near the beginning of the top-level CMakeLists.txt, before any targets are declared. The same concepts and scope apply to compile definitions and linker flags.

By default, add_compile_options() and target_compile_options() add flags for all target languages. Multi-language targets (for example, a target that has C and C++ source files) would have the flags applied to all languages. In general, this may cause problems if the flags are not appropriate for all languages.

The options are restricted by compiler, language, build configuration, etc. using CMake generator expressions. For example, $<COMPILE_LANGUAGE:Fortran> is used to restrict options to Fortran targets. A stanza like $<AND:$<COMPILE_LANGUAGE:Fortran>,$<CONFIG:Debug,RelWithDebInfo>> sets flags for Fortran targets in the debug and RelWithDebInfo build configurations.

Note: where using FetchContent, the main project may desire -Wall but this may cause megabytes of warnings from a legacy Fetched project. A solution is to put add_compile_options() in each of the parent project directories and/or use target_compile_options() in the parent project.

This example is for a C and Fortran project, where some flags apply to C and Fortran, and other flags are Fortran-specific. It’s often useful to use a convenience function to make the code more readable, say in a file “AddOptions.cmake”:

function(add_compile_lang_options lang)

  set(args "")

  foreach(arg ${ARGN})
    string(APPEND args ${arg}$<SEMICOLON>)
  endforeach()

  add_compile_options($<$<COMPILE_LANGUAGE:${lang}>:${args}>)
endfunction()
project(Demo LANGUAGES C Fortran)

include(AddOptions.cmake)

add_compile_lang_options(Fortran -Wall -fimplicit-none)

# more advanced example to add debug-only, compiler-specific and language-specific options:

add_compile_options(
  $<$<AND:$<COMPILE_LANG_AND_ID:Fortran,GNU>,$<CONFIG:Debug,RelWithDebInfo>>:-Werror=array-bounds>
)

FFmpeg merge files into single multichannel file

FFmpeg can merge several files each containing one audio channel into a single file with multiple channels. For example, a multichannel data collection might save each sensor channel into individual files. For data analysis and for practicality to avoid mixing channels from different experiments, it can be useful to combine the individual channel files into a single multichannel file. The amerge filter can merge multiple files into a single multichannel file. . The amerge filter requires all input files to have the same sample rate and format.