从源码构建Qt时如何指定macOS最低SDK版本?
I’ve hit this exact snag before—let’s break down what’s going wrong and how to fix it:
The Root Issue
Qt’s ./configure script reads the MACOSX_DEPLOYMENT_TARGET environment variable the moment you run it, and uses that value to generate all the build configuration files (like Makefiles). If you set the variable after running configure, those files already have the default (or previously detected) OS version baked in—your later export command won’t retroactively change anything.
Correct Build Workflow
To get the minimum SDK version set properly to 10.9, follow these steps in order:
- Clean up any prior build traces (if you’ve already run configure or make):
make distclean - Set the deployment target before running configure:
export MACOSX_DEPLOYMENT_TARGET="10.9" - Run configure (you can optionally add the
-sdkflag to explicitly point to the 10.9 SDK for extra certainty, if you have it installed in Xcode):./configure -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk [your other configure flags] - Start the build:
make -j$(sysctl -n hw.ncpu)
Verify the Fix
Once the build finishes, re-run your otool check to confirm the version matches your expectation:
otool -l lib/QtCore.framework/QtCore | grep LC_VERSION_MIN_MACOSX -A 5
You should now see version 10.9 in the output instead of 10.10.
Quick Extra Tips
- If you skip the
-sdkflag, Qt will use the latest SDK available in your Xcode installation, but still honor theMACOSX_DEPLOYMENT_TARGETfor the minimum supported OS. - For Qt 5.x and newer, you can also use the
QMAKE_MACOSX_DEPLOYMENT_TARGETvariable in project files, but setting the system environment variable before configure is the most reliable way to enforce it across the entire Qt build.
内容的提问来源于stack exchange,提问作者Ad N

