cmake在OS X上找不到gl.h [英] cmake not finding gl.h on OS X

查看:193
本文介绍了cmake在OS X上找不到gl.h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OS X 10.10上并尝试使用GLUT和OpenGL构建C项目". 我将其简化为一个展示我的问题的最小示例.我有以下CMakeLists.txt:

I am on OS X 10.10 and trying to build a C 'project' with GLUT and OpenGL. I reduced it to a minimal example showcasing my problem. I have the following CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)
FIND_PACKAGE(OpenGL REQUIRED)
FIND_PACKAGE(GLUT REQUIRED)

if(OpenGL_FOUND) # never true, but printed as true
    link_directories(${OpenGL_LIBRARY_DIRS})
    include_directories(${OpenGL_INCLUDE_DIR})
endif(OpenGL_FOUND)

if(GLUT_FOUND)
    link_directories(${GLUT_LIBRARY_DIR})
    include_directories(${GLUT_INCLUDE_DIR})
endif(GLUT_FOUND)

# print all vars because wtf
get_cmake_property(_v VARIABLES)
foreach(_v ${_v})
   message(STATUS "${_v}=${${_v}}")
endforeach()


add_executable(main main.c)

target_link_libraries(main ${GLUT_LIBRARY} ${OPENGL_LIBRARY})

main.c只是一个包含两个标头的虚拟对象:

The main.c is just a dummy including two headers:

#include <gl.h>
#include <glut.h>
int main()
{    
   return 0;
}

现在,cmake .运行正常,出于调试目的,将打印所有变量.我从某个地方获取了代码,我对cmake的了解还不够,无法知道它是否在做我认为的事情.无论如何,运行make返回

Now, cmake . runs fine and for debugging purposes prints all variables. I took the code from somewhere, I do not know enough about cmake to know whether it's doing what I think it is. Anyway, running make returns

main.c:1:10: fatal error: 'gl.h' file not found
#include <gl.h>
         ^
1 error generated.

标头gl.h实际上存在于/System/Library/Frameworks/OpenGL.framework/Headers中,因此应该通过cmake找到,尤其是因为glut.h具有相同的结构(只需用GLUT替换OpenGL),并且发现就可以了.另外,令我感到困惑的是,从未执行过if(GLUT_FOUND)...中的块(尝试在其中放入message语句),但是在打印变量中却显示为OPENGL_FOUND=TRUE.但是删除if条件不会改变任何内容.

The header gl.h is actually present in /System/Library/Frameworks/OpenGL.framework/Headers and as such should be found by cmake, especially since glut.h is in the same structure (simply replace OpenGL with GLUT) and is found just fine. Also, what is confusing to me is that the block in if(GLUT_FOUND)... is never executed (try to put a message statement into it), but among the printed variables it says OPENGL_FOUND=TRUE. But removing the if-condition does not change anything.

实际问题:到底是怎么回事?为什么a)除非明确包含,否则cake找不到标题; b)尽管OPENGL_FOUND打印为TRUE时,if块仍未执行,c)glut.h没有此类问题?花了几个小时,无法理解为什么.

The actual question: What the hell is going on? Why does a) cmake not find the header unless specifically included, b) the if-block not execute although OPENGL_FOUND prints as TRUE, c) no such problems occur with glut.h? Spent hours on this and can't fathom why.

推荐答案

正如pmr指出的那样,CMake变量区分大小写,因此必须查询变量OPENGL_FOUND. 另外,正如PeterT所写,标头在OS X上作为#include <OpenGL/gl.h>包含在内.

As pointed out bei pmr, CMake variables are case-sensitive, so the variable OPENGL_FOUND must be queried. Also, as PeterT wrote, the header is included as #include <OpenGL/gl.h> on OS X.

这篇关于cmake在OS X上找不到gl.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆