C development environment on Windows
How to create a more unix-like development environment on Windows.
Install MSYS2
- Download MSYS2.
- Check checksum:
certutil -hashfile msys2-x86_64-20210725.exe SHA256
. - Install.
- Run MSYS2.
- Update package database:
pacman -Syu
. - Run “MSYS2 MSYS App” from Start menu.
- Update the rest of the base packages with
pacman -Su
. - Close “MSYS2 MSYS” window.
- To pin to taskbar, open “MSYS2 MinGW 64-bit” from start menu, right click on
icon, “pin to taskbar”, right click on terminal icon and set properties/target
to
C:\msys64\msys2_shell.cmd -mingw64
.
Install Emacs
-
Open MSYS MinGW 64-bit.
-
Install Emacs:
pacman -S mingw-w64-x86_64-emacs
. -
Start Emacs:
emacs
. -
In Emacs install MELPA: Create
~/.emacs.d/init.el
viaCtrl-x Ctrl-f ~/.emacs.d/init.el
:(require ‘package) (add-to-list ‘package-archives ‘(“melpa-stable” . “https://stable.melpa.org/packages/") t) (package-initialize)
-
Save file via
Ctrl-x Ctrl-s
. -
Evaluate init.el via
M-x eval-buffer
. -
Update packages via
M-x package-refresh-contents
. -
If you get
Failed to verify signature archive-contents.sig:
duringM-x package-refresh-contents
, download latest package gnu-elpa-keyring-update from here and install viaM-x package-install-file
and select the downloaded .tar. After this,M-x package-refresh-contents
should run fine.
Install Solarized theme
- Install Solarized theme via
M-x package-install solarized-theme
. - Activate theme via
M-x customize-themes
(answer prompts withy
). - Click on
Save Theme Settings
.
Further settings
- Open
~/.emacs.d/init.el
viaCtrl-x Ctrl-f ~/.emacs.d/init.el
. - Add the following settings:
- Deactivate startup splash screen via
(setq inhibit-startup-message t)
. - Deactivate menu bar via
(menu-bar-mode -1)
. - Deactivate tool bar via
(tool-bar-mode -1)
. - Deactive scroll bars via
(scroll-bar-mode -1)
. - Deacticate cursor blinking via
(blink-cursor-mode -1)
. - Activate column number mode via
(column-number-mode 1)
.
- Deactivate startup splash screen via
- Activate settings via
M-x eval-buffer
. - Full
~/.emacs.d/init.el
so far:
|
|
Install Clang
- Install Clang via
pacman -S mingw-w64-x86_64-clang
. (You can do this from Emacs via eshell now:M-x eshell
.) - Create sample application via
Ctrl-x Ctrl-f hello.c
:
|
|
- Compile with
clang -include stdio.h hello.c -o hello
. - Run with
hello
,hello.exe
or./hello.exe
.
Install GDB
- Install GDB via
pacman -S mingw-w64-x86_64-gdb
. - Create sample application:
|
|
- Save as
10.c
. - Compile via
clang -g 10.c -o 10
. - In Emacs start gdb via
M-x gdb
. - In gdb load symbols via
file 10
. - Set breakpoint in line 4 via
break 10.c:4
. - Start program via
r
. - When breakpoint is hit, print x via
print x
. - x will be 0.
- Move to next instruction via
n
. print x
will show x is 10.- Quit debugging with
q
or continue till end of execution viac
.
Install GNU Make
- Install GNU Make via
pacman -S make
. - Create sample application:
|
|
|
|
|
|
- Create file
Makefile
:
|
|
- Load
main.c
orlibrary.c
in Emacs and build the program viaM-x compile RET make -k RET
. - (If you get something like
Makefile ... missing separator
, you didn’t use tabs in your Makefile.) - Run program via
M-x compile RET make run RET
. - To clean up and recompile all files perform
M-x compile RET make clean RET
.
Install git
- Install git:
pacman -S git
. - Set up git user credentials via:
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
Install Magit
- In Emacs install Magit via
M-x package-install RET magit RET
. - Create repository:
M-x magit-init
. - Add files via
M-x magit-stage
or open Magit buffer viaM-x magit
and stage files vias
. - Commit changes via
M-x magit-commit RET c
or open Magit buffer withM-x magit
and commit viac
, enter a commit message andCtrl-C Ctrl-C
to commit (if you don’t enter a commit message, commit will fail). - View changes via
M-x magit-diff RET d RET
. - Revert changes of opened file via
M-x magit-file-checkout
. - Use
M-x magit
while file of repository opened to open an overview of a repository.
Install Doxygen
- Install Doxygen via
pacman -S mingw-w64-x86_64-doxygen
. - Create Doxygen configuration file with
doxygen -g
. - Sample code with Doxygen documentation (
\file
has to be at beginning of file):
|
|
- Create documentation via
doxygen
. - Documentation is created in directories
html
andlatex
.