Opengl 如何使用cmake在OSX上链接libGL?
我试图在OSX 10.11上编译,在经历了一些与X11相关的依赖项的困难之后,我发现自己仍然遇到了一些链接错误:Opengl 如何使用cmake在OSX上链接libGL?,opengl,cmake,linker-errors,x11,glx,Opengl,Cmake,Linker Errors,X11,Glx,我试图在OSX 10.11上编译,在经历了一些与X11相关的依赖项的困难之后,我发现自己仍然遇到了一些链接错误: Undefined symbols for architecture x86_64: "_glXChooseVisual", referenced from: vis::OpenGLContextGLX::InitializeWindowless(vis::OpenGLContextImpl*) in opengl_context_glx.cc.o
Undefined symbols for architecture x86_64:
"_glXChooseVisual", referenced from:
vis::OpenGLContextGLX::InitializeWindowless(vis::OpenGLContextImpl*) in opengl_context_glx.cc.o
"_glXCreateContext", referenced from:
vis::OpenGLContextGLX::InitializeWindowless(vis::OpenGLContextImpl*) in opengl_context_glx.cc.o
"_glXDestroyContext", referenced from:
vis::OpenGLContextGLX::Deinitialize() in opengl_context_glx.cc.o
"_glXGetCurrentContext", referenced from:
vis::IsOpenGLContextAvailable() in opengl.cc.o
vis::OpenGLContextGLX::AttachToCurrent() in opengl_context_glx.cc.o
"_glXGetCurrentDisplay", referenced from:
vis::OpenGLContextGLX::AttachToCurrent() in opengl_context_glx.cc.o
"_glXGetCurrentDrawable", referenced from:
vis::OpenGLContextGLX::AttachToCurrent() in opengl_context_glx.cc.o
"_glXMakeCurrent", referenced from:
vis::OpenGLContextGLX::MakeCurrent() in opengl_context_glx.cc.o
ld: symbol(s) not found for architecture x86_64
我发现libGL.dylib
有以下符号:
for lib in /usr/X11R6/lib/*.dylib;do nm -gU $lib | grep _glXChooseVisual;done
000000000000307f T _glXChooseVisual
000000000000307f T _glXChooseVisual
gp:src George$ for lib in /usr/X11R6/lib/*.dylib;do echo $lib && nm -gU $lib | grep _glXChooseVisual;done
/usr/X11R6/lib/libAppleWM.7.dylib
/usr/X11R6/lib/libAppleWM.dylib
/usr/X11R6/lib/libFS.6.dylib
/usr/X11R6/lib/libFS.dylib
/usr/X11R6/lib/libGL.1.dylib
000000000000307f T _glXChooseVisual
/usr/X11R6/lib/libGL.dylib
000000000000307f T _glXChooseVisual
然而,我似乎无法调整CMakeLists.txt来考虑这一点
我尝试添加:
set(X11R6_INCLUDE_DIRS "/usr/X11R6/include")
set(X11R6_LIBRARIES "/usr/X11R6/lib")
我后来在调用libvis
的target\u include\u目录和target\u链接库时使用了它,但似乎没有起到作用
在目标链接库中非法添加-lGL
会导致ld:library not found for-lGL
我也看过并尝试过使用find\u包(OpenGL必需的组件OpenGL GLX)
,但没走多远:
CMake Error at /usr/local/Cellar/cmake/3.18.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:165 (message):
Could NOT find OpenGL (missing: GLX)
关于通过OSX上的CMake正确链接GLX的任何提示?在macOS上都不会(!)针对X11/GLX开发。它们不是本机支持的!用于macOS的X11服务器仅支持功能有限的间接GLX。你只会得到低于标准的表现。并且不支持CUDA(由libvis使用)
在macOS上,所有OpenGL开发都应使用本机OpenGL
框架:
但是请注意,OpenGL已经被苹果宣布为不推荐使用
简言之:您至少需要修改您的程序以使用macOS OpenGL框架,甚至必须咬紧牙关接受macOS不是您应用程序的良好支持平台。这听起来像是合理的建议(+1)