Labels

Android (1) Apache (1) bash (2) boost (2) C (36) C++ (4) cheatsheet (2) CLion (6) css (3) Debian (33) DL (17) Docker (3) Dreamweaver (2) Eclipse (3) fail2ban (5) git (6) GitHub (5) Hacking (4) html (8) http (1) iOS (1) iPad (1) IRC (1) Java (33) javascript (3) Linux (177) Mac (21) Machine Learning (1) mySQL (52) Netbeans (6) Networking (1) Nexus (1) OpenVMS (6) Oracle (2) Pandas (3) php (17) Postgresql (8) Python (9) raid (1) RedHat (14) Samba (2) Slackware (50) SQL (14) svn (1) tar (1) ThinkPad (1) Virtualbox (4) Visual Basic (2) Visual Studio (1) Windows (4)

Friday, 24 April 2026

Target windows XP from Mac using Netbeans and Docker

I had tried building C/C++ applications for Windows XP using my Mac and mingw-w64 installed using Home-brew but it just didnt work out. This mostly resulted in the following when trying to run the executable on Windows XP;


What I finally discovered and use is, setting up a Docker image with the appropriate XP-compatible toolchain, ie. a MinGW that targets MSVCRT, not UCRT.

1) Setup the Docker image.

The files can be found under mingw-xp from https://github.com/plisken1/docker-projects which includes a Dockerfile and a control script my-mingw-xp.sh.

Usage: my-mingw-xp.sh build

which builds the Image and then creates a new container from that image and starts it.

2) Standalone Usage.

The script when used with  my-mingw-xp.sh build does:

(a) Builds the Image:
docker build --no-cache -t "$IMAGE_NAME" . via the function create_image()

(b) Creates a new container from that image and starts it:
docker run --rm -it -v "$PWD":/netbeans  "$IMAGE_NAME" via the function run_container()

The container can be started using my-mingw-xp.sh run and not by using  y-mingw-xp.sh start as would normally be the case. This is because the container is removed when exited (the --rm switch).
The actual docker command used is: docker run --rm -it -v "$PWD":/netbeans  "$IMAGE_NAME" where the Image name is my-mingw-xp-image

Note: See the Dockerfile for additional applications installed when the image is built.

3) Netbeans Integration.

A Makefile has been created which can be found in the above repository, which will build a *.c or *.cpp file from within Netbeans using the Docker container.

An example structure for the placement of the Makefile is below;



The Docker command that builds the *.c or *.cpp file is (using main.c and main.exe as examples):

docker run --rm -v "$(shell pwd)":/netbeans -w /netbeans my-mingw-xp-image i686-w64-mingw32-gcc main.c -Wall -o main.exe && i686-w64-mingw32-objdump -p $@ | grep Subsystem

This command also runs the i686-w64-mingw32-objdump -p $@ | grep Subsystem which provides output about the binary, specifically the MajorSubsystemVersion (I believe 4 is Windows NT)

The above command can be run from a terminal at location where the source (*.c/*.cpp) file is located or we can simply build or clean and build from Netbeans.

An example of a clean and build from within Netbeans is as below:

cd '/Volumes/D_SLAVE/My Documents/My Projects/NetBeansProjects/start_up'
/usr/bin/make -f Makefile CONF=Debug clean
rm -f *.exe
rm -rf dist/

CLEAN SUCCESSFUL (total time: 117ms)
cd '/Volumes/D_SLAVE/My Documents/My Projects/NetBeansProjects/start_up'
/usr/bin/make -f Makefile CONF=Debug

Compiling C source main.c...
docker run --rm -v "/Volumes/D_SLAVE/My Documents/My Projects/NetBeansProjects/start_up":/netbeans -w /netbeans my-mingw-xp-image i686-w64-mingw32-gcc main.c -o main.exe -Wall && i686-w64-mingw32-objdump -p main.exe | grep Subsystem
MajorSubsystemVersion 4
MinorSubsystemVersion 0
Subsystem 00000003 (Windows CUI)
cp main.exe dist/Docker/main.exe
rm main.exe

BUILD SUCCESSFUL (total time: 11s)





No comments:

Post a Comment

Note: only a member of this blog may post a comment.