MacOS cmake无法找到_package(OpenGL)

gk7wooem  于 2023-08-04  发布在  Mac
关注(0)|答案(2)|浏览(239)

在某个时候cmake停止查找OpenGL并显示此错误消息
第一个月
然后我将CMAKE_FIND_DEBUG_MODE设置为true,然后我意识到cmake没有在frameworks文件夹中查找
message("${CMAKE_FRAMEWORK_PATH}")打印空字符串
CMAKE_FRAMEWORK_PATH设置为/System/Library/Frameworks后,cmake仍然无法找到OpenGL
Could NOT find OpenGL (missing: OPENGL_INCLUDE_DIR)
因此,我有两个问题:
1.为什么CMAKE_FRAMEWORK_PATH是一个空字符串(应该是吗?))
1.为什么即使指定了frameworks文件夹,CMake也找不到OpenGL头文件

soat7uwm

soat7uwm1#

1.为什么CMAKE_FRAMEWORK_PATH是一个空字符串(应该是吗?))
一般来说,是的,它应该是空的。如果您在非标准位置安装了框架,则只需要设置CMAKE_FRAMEWORK_PATH
为什么即使指定了frameworks文件夹,CMake也找不到OpenGL头文件
/System/Library/Frameworks不是头文件所在的位置。它们位于您的目标SDK中,为此您需要安装XCode或命令行工具。

$ find /System/Library/Frameworks/ -name gl.h
$ find /Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/ -name gl.h
/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk//System/Library/Frameworks/OpenGL.framework/Versions/A/Headers/gl.h

字符集
基本CMakeLists.txt

cmake_minimum_required(VERSION 3.27.0 FATAL_ERROR)
include(CMakePrintHelpers)
project(t)

cmake_print_variables(OPENGL_gl_LIBRARY)
cmake_print_variables(OPENGL_INCLUDE_DIR)
cmake_print_variables(CMAKE_FRAMEWORK_PATH)
find_package(OpenGL)
cmake_print_variables(OPENGL_gl_LIBRARY)
cmake_print_variables(OPENGL_INCLUDE_DIR)
cmake_print_variables(CMAKE_FRAMEWORK_PATH)


你会得到:

$ rm -rf CMakeCache.txt CMakeFiles/; cmake --version ; cmake .
cmake version 3.27.0

CMake suite maintained and supported by Kitware (kitware.com/cmake).
-- The C compiler identification is AppleClang 14.0.0.14000029
-- The CXX compiler identification is AppleClang 14.0.0.14000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- OPENGL_gl_LIBRARY=""
-- OPENGL_INCLUDE_DIR=""
-- CMAKE_FRAMEWORK_PATH=""
-- Found OpenGL: /Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/OpenGL.framework
-- OPENGL_gl_LIBRARY="/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/OpenGL.framework"
-- OPENGL_INCLUDE_DIR="/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/System/Library/Frameworks/OpenGL.framework"
-- CMAKE_FRAMEWORK_PATH=""
-- Configuring done (0.5s)
-- Generating done (0.0s)
-- Build files have been written to: /tmp

$

zpjtge22

zpjtge222#

问题是我试图在CMakeLists.txt中的项目之前调用find_package
以这种方式重新排序代码行:

project("name")
find_package(OpenGL REQUIRED)

字符集
解决了我的问题

相关问题