Build Guide
Note
This document was generated by AI and may contain errors or incomplete parts.
This document details how to build the DesktopDanmaku project, including setting up the build environment, build commands, and common issues during the build process.
1. Build Environment
1.1 Required Tools
- Operating System: Windows 10 or later
- C++ Compiler: A compiler supporting C++17, callable via the g++ command (such as GCC, MinGW-w64, etc.)
- GNU Make: For executing build commands
1.2 Recommended Tools
- MSYS2: Provides MingGW64 compilation environment (optional, convenient for obtaining g++ compiler)
1.3 Environment Setup
1.3.1 Installing C++ Compiler
Here are the methods to install a C++ compiler on Windows systems, ensuring it can be called via the g++ command. You have two options:
Option 1: Using MSYS2 (Recommended, most convenient way on Windows)
- Download and install the Windows version of MSYS2 from MSYS2 official website
- After installation, open the MSYS2 MSYS terminal
- Run the following command to update system packages:
pacman -Syu- Restart the terminal and run the update command again:
pacman -Syu- Install the MingGW64 toolchain (including g++ compiler):
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-make- Add
C:\msys64\mingw64\binto the system environment variablePATH
Option 2: Directly Installing MinGW-w64
- Download the Windows version of MinGW-w64 from MinGW-w64 official website
- Run the installer and select the appropriate architecture and version
- Add the
binfolder under the installation directory to the system environment variablePATH
1.3.2 Installing GNU Make
If after installing MinGW-w64 using Option 2, running make --version shows the command not found, you need to install GNU Make separately:
- Download the installer from GNU Make for Windows
- Run the installer
- Add the
binfolder under the installation directory to the system environment variablePATH
1.3.3 Verifying Environment Installation
Run the following commands in the command prompt to verify if the compiler is installed successfully:
g++ --version
make --version2. Building the Project
2.1 Basic Build Commands
Run the following commands in the project root directory:
2.1.1 Building DEBUG Version (Default 64-bit)
makeThis will generate the executable file danmaku.exe in the build/64/debug directory.
2.1.2 Building 32-bit DEBUG Version
make ARCH=32This will generate the 32-bit executable file danmaku.exe in the build/32/debug directory.
2.1.3 Building RELEASE Version (64-bit)
make DEBUG=0This will generate the optimized executable file danmaku.exe in the build/64/release directory.
2.1.4 Building 32-bit RELEASE Version
make ARCH=32 DEBUG=0This will generate the optimized 32-bit executable file danmaku.exe in the build/32/release directory.
2.2 Build Options
| Option | Description | Default Value |
|---|---|---|
| ARCH | Architecture, supports 32 or 64 | 64 |
| DEBUG | Whether to build debug version, 1 for yes, 0 for no | 1 |
| CXX | C++ compiler | 64-bit: g++, 32-bit: i686-w64-mingw32-g++ |
| CXXFLAGS | C++ compiler flags | -std=c++17 -Wall -Wextra -Wpedantic |
| LDFLAGS | Linker flags | -mwindows -municode |
| LDLIBS | Link libraries | -luser32 -lgdi32 -lcomctl32 -lgdiplus |
2.3 Other Build Targets
2.3.1 Viewing Help Information
make helpDisplays makefile help information (actually displays the content of docs/makefileHelper.txt file).
2.3.2 Cleaning Build Files
make cleanDeletes all build-generated files and directories (the entire build directory).
2.3.3 Running Compiled Results
make runCompiles and runs the program (default runs the 64-bit version).
2.3.4 Building All Release Versions
make releaseCleans and builds 64-bit and 32-bit release versions.
2.3.5 Building 64-bit Release Version
make release64Builds 64-bit release version.
2.3.6 Building 32-bit Release Version
make release32Builds 32-bit release version.
2.3.7 Building Installation Packages
make installerCleans and builds 64-bit and 32-bit installation packages.
2.3.8 Building 64-bit Installation Package
make installer64Builds 64-bit installation package.
2.3.9 Building 32-bit Installation Package
make installer32Builds 32-bit installation package.
3. Detailed Build Process
3.1 Build Directory Structure
The build process creates a build directory in the project root directory, and creates subdirectories based on architecture and build type:
build/
โโโ 64/
โ โโโ debug/ # 64-bit debug version
โ โ โโโ obj/ # Object file directory
โ โ โโโ danmaku.exe # Executable file
โ โโโ release/ # 64-bit release version
โ โโโ obj/ # Object file directory
โ โโโ danmaku.exe # Executable file
โโโ 32/
โโโ debug/ # 32-bit debug version
โ โโโ obj/ # Object file directory
โ โโโ danmaku.exe # Executable file
โโโ release/ # 32-bit release version
โโโ obj/ # Object file directory
โโโ danmaku.exe # Executable file3.2 Build Flow
- Checks if the build directory exists, creates it if not
- Compiles source files, generates object files (stored in obj directory)
- Compiles resource files (src/list.rc), generates manifest.o
- Links all object files and resource files, generates executable file danmaku.exe
- After build completion, displays build result information
3.3 Dependency Management
The project uses makefile to automatically manage dependencies. When source files or header files change, it automatically recompiles related files.
4. Common Issues and Solutions
4.1 Build Failures
4.1.1 Compiler Not Found
Error Message:
make: gcc: Command not foundSolution:
- Check if MSYS2 and MingGW64 are installed correctly
- Check if the environment variable
PATHincludesC:\msys64\mingw64\bin - Try reopening the command prompt to ensure environment variables take effect
4.1.2 Header File Not Found
Error Message:
fatal error: danmaku/dmkitem.hpp: No such file or directorySolution:
- Check if the project directory structure is correct
- Ensure header file paths are under the include directory
- Check include path settings in makefile
4.1.3 Link Error
Error Message:
undefined reference to `GdiplusStartup'Solution:
- Check if the GDI+ library is linked correctly
- Ensure the LIBS variable in makefile includes
-lgdiplus
4.2 Runtime Errors
4.2.1 Missing DLL Files
Error Message:
This program cannot start because libgcc_s_seh-1.dll is missing from your computer.Solution:
- Copy DLL files from MSYS2 to the executable file directory
- Or add the MSYS2 bin directory to the system environment variable
PATH
4.2.2 Permission Error
Error Message:
Access denied.Solution:
- Run the command prompt or executable as administrator
- Check file and directory permission settings
5. Advanced Build Options
5.1 Custom Compilation Flags
You can customize compilation flags via command line parameters:
make CXXFLAGS="-Wall -Wextra -g -std=c++17 -O2"5.2 Parallel Build
Using the -j option enables parallel build to speed up the build process:
make -j4Where 4 is the number of parallel tasks, which can be adjusted according to the number of CPU cores.
5.3 Cross Compilation
The project supports cross-compilation, allowing you to build 32-bit versions on 64-bit systems:
make ARCH=326. Build Scripts
6.1 Batch Scripts
You can create batch scripts to simplify the build process, for example:
build_debug.bat:
@echo off
make
pausebuild_release.bat:
@echo off
make RELEASE=1
pause6.2 PowerShell Scripts
build_debug.ps1:
make
Read-Host "Press Enter to continue..."build_release.ps1:
make RELEASE=1
Read-Host "Press Enter to continue..."7. Continuous Integration
If you need to set up continuous integration, you can refer to the following configuration:
7.1 GitHub Actions
Create a .github/workflows/build.yml file in the project root directory:
name: Build
on:
push:
branches: [ main, dev ]
pull_request:
branches: [ main, dev ]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Set up MSYS2
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
update: true
install: >-
mingw-w64-x86_64-gcc
mingw-w64-x86_64-make
- name: Build DEBUG
shell: msys2 {0}
run: make
- name: Build RELEASE
shell: msys2 {0}
run: make RELEASE=1
- name: Build 32-bit DEBUG
shell: msys2 {0}
run: make ARCH=32
- name: Build 32-bit RELEASE
shell: msys2 {0}
run: make ARCH=32 RELEASE=18. Summary
This guide details the build process of the DesktopDanmaku project, including environment setup, build commands, and solutions to common issues. By following this guide, you should be able to successfully build the project and resolve issues encountered during the build process.
If you encounter other issues during the build process, please refer to the project’s GitHub Issues page or contact the project maintainer.
We hope this guide is helpful to you!