Skip to content

Commit a338a88

Browse files
committed
Fix Windows/MSYS2/MinGW64 build failures (issue #280)
Add MSYS environment support to configure.ac so users building from the MSYS shell get proper Windows configuration (winsock2.h, ws2_32 lib) instead of falling through to the Unix case (arpa/inet.h). Changes: - configure.ac: Add *-msys* case with Windows config and warning about msys-2.0.dll dependency - configure.ac: Add host triplet and Windows build status to summary - appveyor.yml: Add MSYS environment to CI matrix alongside MinGW64 - README.md: Add Windows/MSYS2 build section with step-by-step instructions and explanation of shell differences
1 parent cbf6bfd commit a338a88

File tree

3 files changed

+80
-10
lines changed

3 files changed

+80
-10
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,53 @@ Here are listed the libhttpserver specific options (the canonical configure opti
119119

120120
[Back to TOC](#table-of-contents)
121121

122+
### Building on Windows (MSYS2)
123+
124+
MSYS2 provides multiple shell environments with different purposes. Understanding which shell to use is important:
125+
126+
| Shell | Host Triplet | Runtime Dependency | Use Case |
127+
|-------|--------------|-------------------|----------|
128+
| **MinGW64** | `x86_64-w64-mingw32` | Native Windows | **Recommended** for native Windows apps |
129+
| **MSYS** | `x86_64-pc-msys` | msys-2.0.dll | POSIX-style apps, build tools |
130+
131+
**Recommended: Use the MinGW64 shell** for building libhttpserver to produce native Windows binaries without additional runtime dependencies.
132+
133+
#### Step-by-step build instructions
134+
135+
1. Install [MSYS2](https://www.msys2.org/)
136+
137+
2. Open the **MINGW64** shell (not the MSYS shell) from the Start Menu
138+
139+
3. Install dependencies:
140+
```bash
141+
pacman -S --needed mingw-w64-x86_64-{gcc,libtool,make,pkg-config,doxygen,gnutls,curl} autotools
142+
```
143+
144+
4. Build and install [libmicrohttpd](https://www.gnu.org/software/libmicrohttpd/) (>= 0.9.64)
145+
146+
5. Build libhttpserver:
147+
```bash
148+
./bootstrap
149+
mkdir build && cd build
150+
../configure --disable-fastopen
151+
make
152+
make check # run tests
153+
```
154+
155+
**Important:** The `--disable-fastopen` flag is required on Windows as TCP_FASTOPEN is not supported.
156+
157+
#### If you use the MSYS shell
158+
159+
Building from the MSYS shell also works but the resulting binaries will depend on `msys-2.0.dll`. The configure script will display a warning when building in this environment. If you see:
160+
161+
```
162+
configure: WARNING: Building from MSYS environment. Binaries will depend on msys-2.0.dll.
163+
```
164+
165+
Consider switching to the MinGW64 shell for native Windows binaries.
166+
167+
[Back to TOC](#table-of-contents)
168+
122169
## Getting Started
123170
The most basic example of creating a server and handling a requests for the path `/hello`:
124171
```cpp

appveyor.yml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ platform: x64
22

33
environment:
44
matrix:
5-
- compiler: msys2
5+
- compiler: mingw64
66
MINGW_CHOST: x86_64-w64-mingw32
77
MSYS2_ARCH: x86_64
8+
MSYS2_SHELL: mingw64
9+
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
10+
- compiler: msys
11+
MINGW_CHOST: x86_64-pc-msys
12+
MSYS2_ARCH: x86_64
13+
MSYS2_SHELL: msys
814
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
915
init:
1016
- 'echo Building libhttpserver %version% for Windows'
@@ -15,13 +21,18 @@ init:
1521
- 'echo Cygwin root is: %CYG_ROOT%'
1622
- ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
1723
install:
18-
- 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -msys2 -c "pacman --noconfirm -S --needed mingw-w64-$MSYS2_ARCH-{libtool,make,pkg-config,libsystre,doxygen,gnutls,graphviz,curl}"'
19-
- 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -msys2 -c "pacman --noconfirm -S --needed autotools"'
20-
- 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -mingw64 -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER && curl https://s3.amazonaws.com/libhttpserver/libmicrohttpd_releases/libmicrohttpd-0.9.64.tar.gz -o libmicrohttpd-0.9.64.tar.gz"'
21-
- 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -mingw64 -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER && tar -xzf libmicrohttpd-0.9.64.tar.gz"'
22-
- 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -mingw64 -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER/libmicrohttpd-0.9.64 && ./configure --disable-examples --enable-poll=no --prefix /C/msys64 && make && make install"'
23-
- 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -mingw64 -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER && ./bootstrap"'
24-
- 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -mingw64 -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER && mkdir build && cd build && MANIFEST_TOOL=no; ../configure --disable-fastopen --prefix /C/msys64 CXXFLAGS=-I/C/msys64/include LDFLAGS=-L/C/msys64/lib; make"'
24+
# Install packages (use msys2 shell for package management)
25+
- 'C:\msys64\msys2_shell.cmd -defterm -no-start -msys2 -c "pacman --noconfirm -S --needed mingw-w64-$MSYS2_ARCH-{libtool,make,pkg-config,libsystre,doxygen,gnutls,graphviz,curl}"'
26+
- 'C:\msys64\msys2_shell.cmd -defterm -no-start -msys2 -c "pacman --noconfirm -S --needed autotools"'
27+
# For msys shell, also install msys-specific packages
28+
- 'if "%compiler%"=="msys" C:\msys64\msys2_shell.cmd -defterm -no-start -msys2 -c "pacman --noconfirm -S --needed msys2-devel gcc make curl"'
29+
# Download and build libmicrohttpd
30+
- 'C:\msys64\msys2_shell.cmd -defterm -no-start -%MSYS2_SHELL% -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER && curl https://s3.amazonaws.com/libhttpserver/libmicrohttpd_releases/libmicrohttpd-0.9.64.tar.gz -o libmicrohttpd-0.9.64.tar.gz"'
31+
- 'C:\msys64\msys2_shell.cmd -defterm -no-start -%MSYS2_SHELL% -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER && tar -xzf libmicrohttpd-0.9.64.tar.gz"'
32+
- 'C:\msys64\msys2_shell.cmd -defterm -no-start -%MSYS2_SHELL% -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER/libmicrohttpd-0.9.64 && ./configure --disable-examples --enable-poll=no --prefix /C/msys64 && make && make install"'
33+
# Bootstrap and configure libhttpserver
34+
- 'C:\msys64\msys2_shell.cmd -defterm -no-start -%MSYS2_SHELL% -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER && ./bootstrap"'
35+
- 'C:\msys64\msys2_shell.cmd -defterm -no-start -%MSYS2_SHELL% -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER && mkdir build && cd build && MANIFEST_TOOL=no; ../configure --disable-fastopen --prefix /C/msys64 CXXFLAGS=-I/C/msys64/include LDFLAGS=-L/C/msys64/lib; make"'
2536
build_script:
26-
- 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -mingw64 -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER/build && make check"'
27-
- 'if "%compiler%"=="msys2" C:\msys64\msys2_shell.cmd -defterm -no-start -mingw64 -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER/build && cat test/test-suite.log"'
37+
- 'C:\msys64\msys2_shell.cmd -defterm -no-start -%MSYS2_SHELL% -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER/build && make check"'
38+
- 'C:\msys64\msys2_shell.cmd -defterm -no-start -%MSYS2_SHELL% -full-path -here -c "cd $APPVEYOR_BUILD_FOLDER/build && cat test/test-suite.log"'

configure.ac

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ case "$host" in
7171
NETWORK_LIBS="-lws2_32"
7272
native_srcdir=$(cd $srcdir; pwd -W)
7373
;;
74+
*-msys*)
75+
AC_MSG_WARN([
76+
Building from MSYS environment. Binaries will depend on msys-2.0.dll.
77+
For native Windows binaries, use the MinGW64 shell instead.
78+
])
79+
NETWORK_HEADER="winsock2.h"
80+
ADDITIONAL_LIBS="-lpthread -no-undefined"
81+
NETWORK_LIBS="-lws2_32"
82+
native_srcdir=$(cd $srcdir; pwd -W)
83+
;;
7484
*-cygwin*)
7585
NETWORK_HEADER="arpa/inet.h"
7686
ADDITIONAL_LIBS="-lpthread -no-undefined"
@@ -294,11 +304,13 @@ AC_OUTPUT(
294304

295305
AC_MSG_NOTICE([Configuration Summary:
296306
Operating System: ${host_os}
307+
Host triplet : ${host}
297308
Target directory: ${prefix}
298309
License : LGPL only
299310
Debug : ${debugit}
300311
TLS Enabled : ${have_gnutls}
301312
TCP_FASTOPEN : ${is_fastopen_supported}
302313
Static : ${static}
314+
Windows build : ${is_windows}
303315
Build examples : ${enable_examples}
304316
])

0 commit comments

Comments
 (0)