Menu

Build executable setup for Windows on Windows

Dirk Krause
← Previous ↑ Home ↑ Installation Next →

Installation on Windows from source, build packages

Cross-build using MingW64 and NSIS on Fedora

Unpack the sources

Download the dktools-x.y.z.zip file from the “Files” area.
The dktools-x.y.z.tar.gz file does not contain the *.chm help files for Windows!
Unpack the archive.

Change into the new unpacked directory.

Install required package.

As root run

scripts/fedora39-prepare-mingw64

to install the build tools and the required libraries including developer support.

Build the software and create the installer

As normal user run

scripts/fedora39-build-mingw64

to build the programs and create an executable installer.
On success you have a dktools-x.y.z-WINDOWS-version-mingw64-nsis.exe file.
Typically the files are created to be used on Windows 7 and above.

To build executables using all possible features from Windows 10, run

scripts/fedora39-build-mingw64 10

instead to build a dktools-x.y.z-WINDOWS-10-mingw64-nsis.exe file.


Build using Visual Studio and InnoSetup on Windows

Before we start

Overview

Installation from source on Windows is recommended for experienced Windows programmers only.
The procedure below was tested on a 64 bit Windows 11 23H2 system using Visual Studio 2022 Professional.
Warning: The procedure will keep you busy for a while.
A Perl interpreter is required, you can use either Strawberry Perl or ActivePerl.
InnoSetup is required to build an executable setup.

The following library versions are used here:

  • zlib 1.3.1
  • bzip2 1.0.8
  • libpng 1.6.44
  • libjpeg 9f
  • OpenSSL 3.4.0
  • wxWidgets 3.2.6

You should use the most recent stable version of the libraries, for newer library versions you probably have to modify the steps shown below.

C runtime version

C run-time libraries on Windows are available in different flavors:

  • Release / Debug
  • Static / DLL
  • Multi-threaded / single-threaded

The run-time library version is choosen at compile time for a *.c or *.cpp module. The table below shows the compiler switches to choose the run-time configuration.
The linker inspects all involved modules to find the run-time library version required by the modules.
If modules are compiled for different run-time library versions, the linker attempts to add both (or even more) versions to the *.exe file. This results in errors or warnings about duplicated functions or symbols.
All modules - including all library modules - used to build a *.exe files should be compiled using the same run-time configuration.

Library type
Static DLL
Threading
Multi-thread Single-thread Multi-thread
EXE
type
Release /MT /ML /MD
Debug /MTd /ML /MDd

We use static linking to build release versions with multithreading support (/MT) to build DK tools.

Libraries

Source code for some of the required libraries is duplicated in the wxWidgets source code bundle for Windows.
Unfortunately these bundled libraries may be different versions.
When linking GUI applications we can use either the original library versions or the versions bundled with wxWidgets.
Using the the original libraries results in missing symbols required by some wxWidgets modules. Using the bundled libraries results in missing symbols required by some DK tools modules.
So we have to integrate the current versions of the original libraries into wxWidgets.


Directory structure

Source code

We create a directory C:\Temp\sw (create C:\Temp first, if not yet present) and download the following software into this directory:

Software Download
zlib http://www.zlib.net/
bzip2 https://sourceware.org/bzip2/
libpng http://www.libpng.org/pub/png/libpng.html
jpeg http://www.ijg.org
OpenSSL http://www.openssl.org/
wxWidgets http://www.wxwidgets.org/

We prefer *.zip archives over other archive formats.

After unpacking we have the following subdirectories in the C:\Temp\sw directory:

  • bzip2-1.0.8
  • jpeg-9f
  • libpng-1.6.44
  • openssl-3.4.0
  • wxWidgets-3.2.6
  • zlib-1.3.1

Installed libraries

We save the header and library files for all libraries (except wxWidgets) into a directory structure below the c:\p\lib\17.0\x64\MT directory. The directory contains:

  • the Visual Studio short version number (i.e. 17.0 for Visual Studio 2022),
  • the platform to build for (i.e. x64 or x86 for 64 or 32 bit Windows), and
  • the runtime library selection (one from: MT, MD, MTd, or MDd).

The wxWidgets library source and the library and header files are in the c:\p\wxWidgets\3.2.6\17.0\x64\MT directory. Here 3.2.6 is the wxWidgets version number.

mkdir c:\p\lib\17.0\x64\MT
mkdir c:\p\lib\17.0\x64\MT\include
mkdir c:\p\lib\17.0\x64\MT\lib
mkdir c:\p\lib\17.0\x64\MT\bin
mkdir c:\p\wxWidgets\3.2.6\17.0\x64\MT

DK tools installation

The DK tools build and installation procedure create a similar directory
structure in the C:\Krause\Bindist directory containing an
“x64” or “x86” subdirectory in turn containing
an “MT” subdirectory.
The parent directory must exist before starting the build process.

mkdir C:\Krause
mkdir C:\Krause\Bindist

Executable setup

Using the InnoSetup compiler we create executable files in the C:\Temp\Distri directory. This directory must exist before starting InnoSetup.

mkdir C:\Temp
mkdir C:\Temp\Distri

Prepare source tree

Command line window for Visual Studio

Open a command line window (cmd.exe) for Visual Studio.

Option: Visual Studio 2022 Professional Start menu item

Visual Studio 2022
 →  x64 Native Tools Command Prompt for VS 2022

Option: Visual Studio 2019 Professional Start menu item

Visual Studio 2019
 →  x64 Native Tools Command Prompt for VS 2019

Option: Visual Studio 2019
Press Windows-R and type the command:

%comspec% /K "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat"

Option: Visual Studio Express for Desktop 2013 Start menu item
Use the start menu item:

Visual Studio 2013
 →  Visual Studio Tools
 →  VS2013 x64 Cross Tools-Eingabeaufforderung

The name will differ on non-german Windows versions.

Option: Visual Studio Express for Desktop 2013 on 64 bit Windows
Press Windows-R and type the command:

%comspec% /K "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86_amd64

Option: Visual Studio Express for Desktop 2013 on 32 bit Windows
Press Windows-R and type the command:

%comspec% /K "C:\Program Files\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86

Option: Visual Studio Express for Desktop 2012 Start menu item
Use the start menu item:

Microsoft Visual Studio 2012
 →  Visual Studio Tools
 →  VS2012 x64 Cross Tools-Eingabeaufforderung

The name will differ on non-german Windows versions.

Option: Visual Studio Express for Desktop 2012 on 64 bit Windows
Press Windows-R and type the command:

%comspec% /K "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" x86_amd64

Option: Visual Studio Express for Desktop 2012 on 32 bit Windows
Press Windows-R and type the command:

%comspec% /K "C:\Program Files\Microsoft Visual Studio 11.0\VC\vcvarsall.bat" x86

Option: Visual Studio 2008 on 64 bit Windows
Press Windows-R and type the command:

%comspec% /E:ON /V:ON /T:0E /K "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.cmd" /release

In the command window type:

SET VisualStudioVersion=9.0

Option: Visual Studio 2008 on 32 bit Windows
Press Windows-R and type the command:

%comspec% /E:ON /V:ON /T:0E /K "C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.cmd" /release

In the command window type:

SET VisualStudioVersion=9.0

Probably you want to create a desktop icon for the command above.

Change directory

Change into source directory.

C:
cd C:\Temp\sw

zlib

Change directory:

cd zlib-1.2.13
cd win32

Edit makefile.msc, replace -MD by -MT:
Open makefile.msc in your favourite text editor.
Replace

CFLAGS  = -nologo -MD -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC)

by

CFLAGS  = -nologo -MT -W3 -O2 -Oy- -Zi -Fd"zlib" $(LOC)

Go back to previous directory:

cd ..
cd ..

bzip2

Change directory:

cd bzip2-1.0.8

Modify makefile.msc, replace -MD by -MT:
Open makefile.msc in your favourite text editor.
Replace

CFLAGS= -DWIN32 -MD -Ox -D_FILE_OFFSET_BITS=64 -nologo

by

CFLAGS= -DWIN32 -MT -Ox -D_FILE_OFFSET_BITS=64 -nologo

Go back to previous directory:

cd ..

libpng

Change directory:

cd libpng-1.6.40
cd scripts

Modify makefile.vcwin32:
Open makefile.msc in your favourite text editor.

Replace

MODEL=L
CFLAGS=-nologo -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -MD -O2 -W3

by

CFLAGS=-nologo -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -MT -O2 -W3 -IC:\P\LIB\17.0\MT\INCLUDE

Note: Leave the CPPFLAGS entry as is!

Go back one directory:

cd ..

Copy pnglibconf.h:

copy scripts\pnglibconf.h.prebuilt pnglibconf.h

Modify pngstruct.h, correct zlib.h inclusion:
Open pngstruct.h in your favourite text editor.
Replace

#include "zlib.h"

by

#include <zlib.h>

Go back to previous directory:

cd ..

libjpeg

Change directory:

cd jpeg-9d

Create jconfig.h file:

copy jconfig.vc jconfig.h

Modify makefile.msc:
Open makefile.msc in your favourite text editor.

Remove the following line (or put it into a comment):

!include <win32.mak>

Replace

CFLAGS= $(cflags) $(cdebug) $(cvars) -I.

by

CC=CL
cc=CL
CFLAGS= /nologo /MT /O2 -D_X86_=1 -DWIN32 -D_WIN32 -DWIN64=1 -D_WIN64=1 -D_WINNT -D_WIN32_WINNT=0x0500 -D_WIN32_IE=0x0500 -DWINVER=0x0500 -DNDEBUG -I. -c

On 32 bit Windows omit "-DWIN64=1 -D_WIN64=1"!

Go back to previous directory:

cd ..

OpenSSL

Change into directory:

cd openssl-3.1.1

Run configure script:

perl Configure VC-WIN64A --prefix=c:/p/lib/17.0/x64/MT no-shared --openssldir=c:/p/lib/17.0/x64/MT -DUNICODE=1 -D_UNICODE=1

On 32 bit Windows use "VC-WIN32" instead of "VC-WIN64A".

Go back to previous directory:

cd ..

wxWidgets

wxWidgets zlib support

Check version:
In the files C:\Temp\sw\zlib-1.2.13\zlib.h and C:\Temp\sw\wxWidgets-3.2.2.1\src\zlib\zlib.h compare the version numbers. If the version number matches, skip this section and proceed with "wxWidgets libpng support" below.

Replace source archive:

RD /S /Q C:\Temp\sw\wxWidgets-3.2.2.1\src\zlib
mkdir C:\Temp\sw\wxWidgets-3.2.2.1\src\zlib
xcopy C:\Temp\sw\zlib-1.2.11\* C:\Temp\sw\wxWidgets-3.2.2.1\src\zlib\ /S /Y /Q

Correct C:\Temp\sw\wxWidgets-3.2.2.1\build\msw\makefile.vc:
The library objects are listed in the C:\Temp\sw\zlib-1.2.13\win32\Makefile.msc file in the OBJS= and OBJA= sections.
For each *.obj file (i.e. "adler32.obj") there must be a corresponding $(OBJS)\wxzlib_*.obj file (i.e. "$(OBJS)\wxzlib_adler32.obj") in the WXZLIB_OBJECTS= section of the C:\Temp\sw\wxWidgets-3.2.2.1\build\msw\makefile.vc file and a rule how to produce the object module, i.e.:

$(OBJS)\wxzlib_adler32.obj: ..\..\src\zlib\adler32.c
        $(CC) /c /nologo /TC /Fo$@ $(WXZLIB_CFLAGS) ..\..\src\zlib\adler32.c
wxWidgets libpng support

Check version:
In the files C:\Temp\sw\libpng-1.6.40\png.h and C:\Temp\sw\wxWidgets-3.2.2.1\src\png\png.h compare the version numbers. If the version number matches, skip this section and proceed with "wxWidgets jpeg support" below.

Replace source archive:

RD /S /Q C:\Temp\sw\wxWidgets-3.2.2.1\src\png
mkdir C:\Temp\sw\wxWidgets-3.2.2.1\src\png
xcopy C:\Temp\sw\lpng1628\* C:\Temp\sw\wxWidgets-3.2.2.1\src\png\ /S /Y /Q

Correct C:\Temp\sw\wxWidgets-3.2.2.1\build\msw\makefile.vc:
The library objects are listed in the C:\Temp\sw\lpng1628\scripts\makefile.msc file in the OBJS1=, OBJS2= and OBJS3= sections.
For each *$(O) file (i.e. "png$(O)") there must be a corresponding $(OBJS)\wxpng_*.obj file (i.e. "$(OBJS)\wxpng_png.obj") in the WXPNG_OBJECTS= section of the C:\Temp\sw\wxWidgets-3.2.2.1\build\msw\makefile.vc file and a rule how to produce the object module, i.e.:

$(OBJS)\wxpng_png.obj: ..\..\src\png\png.c
        $(CC) /c /nologo /TC /Fo$@ $(WXPNG_CFLAGS) ..\..\src\png\png.c
wxWidgets libjpeg support

Check version:
In the files C:\Temp\sw\jpeg-9e\jpeglib.h and C:\Temp\sw\wxWidgets-3.2.2.1\src\jpeg\jpeglib.h compare the version numbers (JPEG_LIB_VERSION). If the version number matches, skip this section and proceed with "wxWidgets libtiff support" below.

Replace source archive:

RD /S /Q C:\Temp\sw\wxWidgets-3.2.2.1\src\jpeg
mkdir C:\Temp\sw\wxWidgets-3.2.2.1\src\jpeg
xcopy C:\Temp\sw\jpeg-9e\* C:\Temp\sw\wxWidgets-3.2.2.1\src\jpeg\ /S /Y /Q

Correct C:\Temp\sw\wxWidgets-3.2.2.1\build\msw\makefile.vc:
The library objects are listed in the C:\Temp\sw\jpeg-9d\makefile.vc file in the LIBOBJECTS= section. In version 9a this section pulls in definitions from other sections, you have to follow the dependencies.
For each *.obj file (i.e. "jcapimin.obj") there must be a corresponding $(OBJS)\wxjpeg_*.obj file (i.e. "$(OBJS)\wxjpeg_jcapimin.obj") in the WXJPEG_OBJECTS= section of the C:\Temp\sw\wxWidgets-3.2.2.1\build\msw\makefile.vc file and a rule how to produce the object module, i.e.:

$(OBJS)\wxjpeg_jcapimin.obj: ..\..\src\jpeg\jcapimin.c
        $(CC) /c /nologo /TC /Fo$@ $(WXJPEG_CFLAGS) ..\..\src\jpeg\jcapimin.c
Copy wxWidgets sources
mkdir c:\p\wxWidgets\3.2.6\17.0\x64\MT
xcopy c:\temp\sw\wxWidgets-3.2.6\* c:\p\wxWidgets\3.2.6\17.0\x64\MT\ /S /Y

Build and install

zlib

cd zlib-1.3.1
nmake -f win32\makefile.msc zlib.lib
xcopy *.lib c:\p\lib\17.0\x64\MT\lib\ /S /Y
xcopy *.h c:\p\lib\17.0\x64\MT\include\ /S /Y
cd ..

bzip2

cd bzip2-1.0.8
nmake -f makefile.msc lib
xcopy *.lib c:\p\lib\17.0\x64\MT\lib\ /S /Y
xcopy *.h c:\p\lib\17.0\x64\MT\include\ /S /Y
cd ..

libpng

cd libpng-1.6.44
nmake -f scripts\makefile.vcwin32 libpng.lib
xcopy *.lib c:\p\lib\17.0\x64\MT\lib\ /S /Y
xcopy *.h c:\p\lib\17.0\x64\MT\include\ /S /Y
cd ..

libjpeg

cd jpeg-9f
nmake -f makefile.vc libjpeg.lib
xcopy *.lib c:\p\lib\17.0\x64\MT\lib\ /S /Y
xcopy *.h c:\p\lib\17.0\x64\MT\include\ /S /Y
cd ..

OpenSSL

cd openssl-3.1.1
nmake
nmake install
cd ..

wxWidgets

cd \p\wxWidgets\3.2.6\17.0\x64\MT\build\msw
nmake -f makefile.vc BUILD=release UNICODE=1 SHARED=0 RUNTIME_LIBS=static TARGET_CPU=AMD64
cd \temp\sw

On 32 bit Windows omit "TARGET_CPU=AMD64".

DK tools

Build and install locally

Change into the dktools-x.y.z directory:

cd dktools-x.y.z

Optionally rebuild the *.chm files
The *.chm files (help files for Windows) in the archive were created using the chmcmd command from the “Free Pascal” project.
If the

hhc

command is available on your computer, you can use HTML help compiler to rebuild the *.chm files:

config\windows\msvc\build-chm.cmd

Optionally customize the config\windows\msvc\conf.vc configuration file:

Variable Purpose Type Values
TARGET_CPU Platform to build for String x64 or x86.
WINDOWS Windows version to build executables for String One from: 10 8.1 8 7 VISTA XPSP3 XP. Default: 7.
RUNTIME_LIBS C runtime library type String static or dynamic.
BUILD Build type String release or debug.
ZLIB
BZIP2
LIBPNG
LIBJPEG
LIBTIFF
OPENSSL
WXWIDGETS
Library presence Boolean yes or no.
WXWIDGETS_VERSION Full wxWidgets version number String 3.2.1 or alike.
WXWIDGETS_VERS_SHORT Abbreviated major/minor wxWidgets version number String 32 or alike.

No changes should be necessary on the remaining variables.

Build the software:

nmake -f config\windows\msvc\makefile.vc

Instead of editing the conf.vc file in the step above you can provide configuration items on the command line here, like:

nmake -f config\windows\msvc\makefile.vc TARGET_CPU=x64 RUNTIME_LIBS=static BUILD=release

But remember to add the same command line arguments in the next step.

Install current build:

nmake -f config\windows\msvc\makefile.vc install

Add directory to PATH:
Use the system control to add the "C:\Krause\Bindist\x64\bin" directory to the PATH environment variable.

Create executable setup

Change into the C:\Krause\Bindist directory:

cd C:\Krause\Bindist

Run InnoSetup:
Open the user64.iss file and use the

Build
 →  Compile

menu item.

The resulting dktools-win64-x.y.z.exe file is placed in the C:\Temp\Distri directory.

← Previous ↑ Home ↑ Installation Next →

Related

Wiki: Installation

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.