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 my-mingw-xp.sh start as would normally be the case. This is because the container is removed when exited (the --rm switch).
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;
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)
This command creates and starts a container from the Image my-mingw-xp-image and then stops and removes the container once completed, there is no interactive shell, unlike if we were to run my-mingw-xp.sh build
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 or even just do make inside the directory. The whole point of the Makefile is so we dont have to type out that long command.
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.