2

我正在 Mac 上开发 C++ 应用程序并使用 CGL 来初始化 OpenGL:

EGL_CONTEXT EglWrapperMac::CreateContext() {
    EGL_CONTEXT context;
    if (kCGLNoError != CGLCreateContext(m_display, NULL, &context)) {
        throw EXT_EXCEPTION(EGL_WRAPPER_ERROR_CREATE_CTX);
    }
    return context;
}

我也使用 Cmake 来生成 XCode 解决方案。不幸的是,由于缺少所需的库,构建失败。我在 cmake: 中尝试了以下语句 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -framework CGL -framework OpenGL")set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lCGL -lOpenGL")但没有运气。

更新:以下是编译错误:

Undefined symbols for architecture x86_64:

  "_CGLChoosePixelFormat", referenced from:
      EglWrapperMac::EglWrapperMac(EglSetup const&, std::__1::shared_ptr<IEngineWindow>) in libVEngineRenderer.a(EglWrapper.o)
  "_CGLCreateContext", referenced from:
      EglWrapperMac::CreateContext() in libVEngineRenderer.a(EglWrapper.o)
  "_CGLDestroyPixelFormat", referenced from:
      EglWrapperMac::~EglWrapperMac() in libVEngineRenderer.a(EglWrapper.o)
  "_CGLFlushDrawable", referenced from:
      EglWrapperMac::Present() in libVEngineRenderer.a(EglWrapper.o)
  "_CGLGetCurrentContext", referenced from:
      EglWrapperMac::GetCurrentContext() in libVEngineRenderer.a(EglWrapper.o)
  "_CGLReleaseContext", referenced from:
      EglWrapperMac::DeleteContext(_CGLContextObject*) in libVEngineRenderer.a(EglWrapper.o)
  "_CGLSetCurrentContext", referenced from:
      EglWrapperMac::MakeCurrent(_CGLContextObject*) in libVEngineRenderer.a(EglWrapper.o)

我该如何处理?

4

1 回答 1

3

感谢帮助。我能够在cmake中使用以下代码解决问题:

include_directories ( /System/Library/Frameworks )
find_library(OpenGL_LIBRARY OpenGL )
set(EXTRA_LIBS ${OpenGL_LIBRARY})

//add_library (VEngineRenderer STATIC ${RENDER_FILES})

target_link_libraries(VEngineRenderer ${EXTRA_LIBS})
于 2013-10-22T04:14:58.373 回答