You can use ldd to view dependencies, then copy the related dll: https://web.archive.org/web/20240620214721/https://janw.name/posts/3-msys2-dlls/
Here is an example makefile (please use the code in solution https://stackoverflow.com/a/60906375/12291425, or use this gist):
it can save a hassle; create a file named GNUmakefile or Makefile and paste the content, then run make dist:
targets := prog.exe my_library.dll my_plugin.dll CXX := g++ CXXFLAGS := -c -g -O0 -MMD -pedantic -Wall -Wextra -Wconversion -Wno-unused -Wno-unused-parameter -Werror -Wfatal-errors -UNDEBUG -std=c++17 -Wno-missing-braces -Wno-sign-conversion all: $(targets) .PHONY: all %.dll: %.o $(CXX) -shared -g -O0 -o $@ $< # by implicit rule, my_plugin.o will be compiled from my_plugin.cpp # by implicit rule, my_library.o will be compiled from my_library.cpp prog.exe: prog.o my_library.dll g++ -o prog.exe prog.o -g -O0 -L. -lmy_library files := $(wildcard *.dll *.o *.d *.exe) distfiles := $(wildcard dist/*.dll dist/*.exe) clean: rm $(files) 2>/dev/null || true rm $(distfiles) 2>/dev/null || true .PHONY: clean dist: all rm -r dist 2>/dev/null || true mkdir dist 2>/dev/null || true cp *.dll *.exe dist @# extra $ is needed in awk in makefile cd dist; ldd $(targets) | grep /ucrt64 | awk '{print $$3}' | xargs -i cp {} . @# if you make sure you are running UCRT, you can remove the following line cd dist; ldd $(targets) | grep /mingw64 | awk '{print $$3}' | xargs -i cp {} . cd dist; explorer . || true .PHONY: dist To clean up, run make clean.
...