2015-05-29 97 views
0

我想在我的Mac上编译一个OpenGL + OpenCL代码,并在经过大量努力设法获得安装的依赖关系并理解如何链接它们(GLUI,GLUT, OpenCL等)。在OS X上编译OpenGL + OpenCL代码时出现错误

大多数错误被删除,但有3个错误仍然坚持如下图所示:

pranjal:~/parallel-prog$ g++-4.9 mittalp.cpp -fopenmp -framework OpenCL -framework OpenGL -framework GLUI -framework GLUT -w 

mittalp.cpp: In function 'void InitCL()': 
mittalp.cpp:465:69: error: 'wglGetCurrentContext' was not declared in this scope 
    CL_GL_CONTEXT_KHR, (cl_context_properties) wglGetCurrentContext(), 
                    ^
mittalp.cpp:466:62: error: 'wglGetCurrentDC' was not declared in this scope 
    CL_WGL_HDC_KHR, (cl_context_properties) wglGetCurrentDC(), 
                  ^
mittalp.cpp: In function 'void InitGlui()': 
mittalp.cpp:619:37: error: 'FALSE' was not declared in this scope 
    Glui->add_column_to_panel(panel, FALSE); 
            ^

我想我知道所有的编译器标志和无法编译。该代码在朋友的机器上的Windows上运行良好,但在我的Mac OS X上无法运行。我怀疑错误是因为错误中列出的3个函数是特定于Windows的。由于我是OpenGL编程的新手,对于OS X等价函数或Mac上需要什么库才能使这些窗口特定函数有效,我没有太多知识。

我已经添加了C++代码here以供参考:

+1

如果您想要创建平台独立的项目,那么我会建议使用像glfw这样的库,它将在平台相关函数上创建一个抽象层,如'wglGetCurrentContext','glxGetCurrentContext'和'CGLGetCurrentContext' –

+0

@ t.niese:我已下载并安装GLFW。你能告诉我什么是我需要使用的等效函数而不是上面的平台相关函数吗? (或者我需要做更多的更改,而不仅仅是这些?) –

+1

glfw不提供_equivalent_函数,然后可以用作直接替换,它们创建一个抽象层,封装平台特定的函数以创建独立于平台的api。对于glfw页面上的opengl部分,有一个简单的[示例代码](http://www.glfw.org/documentation.html),以及[入门](http://www.glfw.org/docs /latest/quick.html)解释_main_函数的页面。 –

回答

4

下面是我使用的用于初始化OpenCL上下文属性,以使在Windows,OS X和Linux的OpenGL互操作的代码:

#if defined(_WIN32) 

    // Windows                 
    cl_context_properties properties[] = { 
     CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(), 
     CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(), 
     CL_CONTEXT_PLATFORM, (cl_context_properties)platform, 
     0 
    }; 

#elif defined(__APPLE__) 

    // OS X                  
    CGLContextObj  kCGLContext  = CGLGetCurrentContext(); 
    CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext); 

    cl_context_properties properties[] = { 
     CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, 
     (cl_context_properties) kCGLShareGroup, 
     0 
    }; 

#else 

    // Linux                  
    cl_context_properties properties[] = { 
     CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(), 
     CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(), 
     CL_CONTEXT_PLATFORM, (cl_context_properties)platform, 
     0 
    }; 

#endif 
+0

昨天晚上我花了很长时间来弄清楚这一切,现在我也得到了你的答案。 :) 谢谢!我还必须包括以下内容。除此之外,还有'#pragma OPENCL EXTENSION CL_APPLE_gl_sharing:enable'。 –

相关问题