Failed to find “gl.h” 环境
macOS Ventura 13.3.1
Qt 5.15.2
问题描述 出现以下错误:
1 /Applications/ Qt/5.15.2/ clang_64/lib/ cmake/Qt5Gui/ Qt5GuiConfigExtras.cmake:9 : error: Failed to find "gl.h" in "/System/Library/Frameworks/OpenGL.framework/Headers;/System/Library/Frameworks/AGL.framework/Headers" . /Applications/ Qt/5.15.2/ clang_64/lib/ cmake/Qt5Gui/ Qt5GuiConfig.cmake:227 (include ) /Applications/ Qt/5.15.2/ clang_64/lib/ cmake/Qt5Widgets/ Qt5WidgetsConfig.cmake:93 (find_package) /Applications/ Qt/5.15.2/ clang_64/lib/ cmake/Qt5/ Qt5Config.cmake:28 (find_package) CMakeLists.txt:15 (find_package)
解决方案 修改/Applications/Qt/5.15.2/clang_64/lib/cmake/Qt5Gui/Qt5GuiConfigExtras.cmake
文件内容。
将其中的
1 2 3 4 set (_GL_INCDIRS "/System/Library/Frameworks/OpenGL.framework/Headers" "/System/Library/Frameworks/AGL.framework/Headers" )
修改为
1 2 3 4 5 6 set (_GL_INCDIRS "/System/Library/Frameworks/OpenGL.framework/Headers" "/System/Library/Frameworks/AGL.framework/Headers" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/AGL.framework/Versions/Current/Headers" )
也就是多添加两个目录:
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers"
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/AGL.framework/Versions/Current/Headers"
将其中的
1 _qt5gui_find_extra_libs (OPENGL "OpenGL;AGL" "" "/System/Library/Frameworks/OpenGL.framework/Headers;/System/Library/Frameworks/AGL.framework/Headers" )
修改为
1 _qt5gui_find_extra_libs (OPENGL "OpenGL;AGL" "" "/System/Library/Frameworks/OpenGL.framework/Headers;/System/Library/Frameworks/AGL.framework/Headers;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/AGL.framework/Versions/Current/Headers" )
也就是多加入了以下内容:
1 ;/Applications/ Xcode.app/Contents/ Developer/Platforms/ MacOSX.platform/Developer/ SDKs/MacOSX.sdk/ System/Library/ Frameworks/OpenGL.framework/ Versions/Current/ Headers;/Applications/ Xcode.app/Contents/ Developer/Platforms/ MacOSX.platform/Developer/ SDKs/MacOSX.sdk/ System/Library/ Frameworks/AGL.framework/ Versions/Current/ Headers
Could not find any valid SDKs 环境:
macOS Ventura 13.3.1
CMake 3.22
Qt Creator 7.0.2
问题描述 Qt Creator
编译项目时出现以下警告:
1 /Applications/ CMake.app/Contents/ share/cmake-3.22/M odules/Platform/ Darwin-Initialize.cmake:112 : warning: Could not find any valid SDKs in /Applications/ Xcode.app/Contents/ Developer/Platforms/M acOSX.platform/Developer/ SDKs /Applications/ CMake.app/Contents/ share/cmake-3.22/M odules/CMakeSystemSpecificInitialize.cmake:21 (include ) CMakeLists.txt:3 (project )
原因分析 macOS
系统中的.sdk
目录名中不再包含版本号。
解决方案 修改/Applications/CMake.app/Contents/share/cmake-3.22/Modules/Platform/Darwin-Initialize.cmake
文件中的内容。
找到以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 set (_CMAKE_OSX_LATEST_SDK_VERSION "0.0" )file (GLOB _CMAKE_OSX_SDKS RELATIVE "${_CMAKE_OSX_SDKS_DIR}" "${_CMAKE_OSX_SDKS_DIR}/MacOSX*.sdk" )foreach (_SDK ${_CMAKE_OSX_SDKS} ) if (IS_DIRECTORY "${_CMAKE_OSX_SDKS_DIR}/${_SDK}" AND _SDK MATCHES "MacOSX([0-9]+\\.[0-9]+)[^/]*\\.sdk" AND CMAKE_MATCH_1 VERSION_GREATER ${_CMAKE_OSX_LATEST_SDK_VERSION} ) set (_CMAKE_OSX_LATEST_SDK_VERSION "${CMAKE_MATCH_1}" ) endif ()endforeach ()if (NOT _CMAKE_OSX_LATEST_SDK_VERSION STREQUAL "0.0" ) set (_CMAKE_OSX_SYSROOT_DEFAULT "${_CMAKE_OSX_SDKS_DIR}/MacOSX${_CMAKE_OSX_LATEST_SDK_VERSION}.sdk" )else () message (WARNING "Could not find any valid SDKs in ${_CMAKE_OSX_SDKS_DIR}" )endif ()
将其修改为:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 set (_CMAKE_OSX_LATEST_SDK_VERSION "0.0" )file (GLOB _CMAKE_OSX_SDKS RELATIVE "${_CMAKE_OSX_SDKS_DIR}" "${_CMAKE_OSX_SDKS_DIR}/MacOSX*.sdk" )foreach (_SDK ${_CMAKE_OSX_SDKS} ) if (IS_DIRECTORY "${_CMAKE_OSX_SDKS_DIR}/${_SDK}" ) if (_SDK MATCHES "MacOSX([0-9]+\\.[0-9]+)[^/]*\\.sdk" AND CMAKE_MATCH_1 VERSION_GREATER ${_CMAKE_OSX_LATEST_SDK_VERSION} ) set (_CMAKE_OSX_LATEST_SDK_VERSION "${CMAKE_MATCH_1}" ) elseif (_SDK MATCHES "MacOSX.sdk" ) set (_CMAKE_OSX_LATEST_SDK_VERSION "" ) endif () endif ()endforeach ()if (NOT _CMAKE_OSX_LATEST_SDK_VERSION STREQUAL "0.0" OR _CMAKE_OSX_LATEST_SDK_VERSION STREQUAL "" ) set (_CMAKE_OSX_SYSROOT_DEFAULT "${_CMAKE_OSX_SDKS_DIR}/MacOSX${_CMAKE_OSX_LATEST_SDK_VERSION}.sdk" )else () message (WARNING "Could not find any valid SDKs in ${_CMAKE_OSX_SDKS_DIR}" )endif ()
主要修改的地方如下图: