You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MinGW/MSYS下qmake生成Makefile混存Windows路径致执行失败求助

Fixing Mixed Windows/POSIX Path Issues with qmake in MinGW64/MSYS

I've run into this exact path formatting conflict before when working with qmake in MSYS environments—let's break down why this happens and how to fix it.

The Root Cause

When you set DESTDIR=../bin in your .pro file, if you're using a Windows-native qmake binary (not the one compiled for MSYS2), qmake will output Windows-style paths with backslashes (\) in the generated Makefile. But MSYS's shell (bash/sh) treats backslashes as escape characters, so ..\bin gets mangled to ..bin (the \b is interpreted as an escape sequence, effectively removing the backslash and altering the path). That's why you see the error /bin/sh: Zeile 0: cd: ..bin: No such file or directory.

Solutions to Fix the Path Formatting

1. Force POSIX Paths in Your .pro File

Instead of relying on raw relative paths, use qmake's built-in $$PWD variable (which returns the POSIX-style path of your .pro file's directory) to construct DESTDIR:

# Use $$PWD to generate a consistent POSIX relative path
DESTDIR = $$PWD/../bin

This ensures qmake outputs a POSIX-compliant path with forward slashes (/) that MSYS's shell understands.

2. Use MSYS2's Native qmake

If you installed Qt via Windows installers, you're probably using a Windows-native qmake. Switch to MSYS2's packaged qmake instead—install it via pacman:

pacman -S qt5-base  # For Qt5
# Or for Qt6: pacman -S qt6-base

MSYS2's qmake is compiled for the POSIX environment, so it will automatically generate correct forward-slash paths in the Makefile.

3. Force qmake to Output POSIX Paths

If you need to keep using your existing qmake binary, pass the -unix flag when running qmake to enforce POSIX path rules:

qmake -unix your_project.pro

Alternatively, set the QMAKE_USE_POSIX_PATH environment variable before running qmake:

export QMAKE_USE_POSIX_PATH=1
qmake your_project.pro

4. Temporary Workaround: Fix the Makefile Manually

If you need a quick fix (not recommended for long-term use), open the generated Makefile and replace all instances of ..\bin with ../bin. Just note you'll have to redo this every time you re-run qmake.

内容的提问来源于stack exchange,提问作者Jens Luedicke

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:06:36