使用命令行在Mac上构建OpenGL应用程序时出现链接错误

bxgwgixi  于 2022-11-04  发布在  Mac
关注(0)|答案(2)|浏览(179)

我刚开始在Mac上构建命令行。在使用OpenGL、IMGui和GLFW开发跨平台应用程序时,我不断收到链接错误:

Undefined symbols for architecture x86_64:
  "__glfwCreateContextEGL", referenced from:
      __glfwPlatformCreateWindow in libGLFW.a(cocoa_window.o)
  "__glfwCreateContextNSGL", referenced from:
      __glfwPlatformCreateWindow in libGLFW.a(cocoa_window.o)
  "__glfwCreateContextOSMesa", referenced from:
      __glfwPlatformCreateWindow in libGLFW.a(cocoa_window.o)
  "__glfwInitEGL", referenced from:
      __glfwPlatformCreateWindow in libGLFW.a(cocoa_window.o)
  "__glfwInitNSGL", referenced from:
      __glfwPlatformCreateWindow in libGLFW.a(cocoa_window.o)
  "__glfwInitOSMesa", referenced from:
      __glfwPlatformCreateWindow in libGLFW.a(cocoa_window.o)
  "__glfwPlatformCreateMutex", referenced from:
      _glfwInit in libGLFW.a(init.o)
  "__glfwPlatformCreateTls", referenced from:
      _glfwInit in libGLFW.a(init.o)
  "__glfwPlatformDestroyMutex", referenced from:
      _terminate in libGLFW.a(init.o)
  "__glfwPlatformDestroyTls", referenced from:
      _terminate in libGLFW.a(init.o)
  "__glfwPlatformGetTls", referenced from:
      _glfwDestroyWindow in libGLFW.a(window.o)
      __glfwRefreshContextAttribs in libGLFW.a(context.o)
      _glfwMakeContextCurrent in libGLFW.a(context.o)
      _glfwExtensionSupported in libGLFW.a(context.o)
      _glfwGetCurrentContext in libGLFW.a(context.o)
      _glfwSwapInterval in libGLFW.a(context.o)
      _glfwGetProcAddress in libGLFW.a(context.o)
      ...
  "__glfwPlatformLockMutex", referenced from:
      __glfwInputError in libGLFW.a(init.o)
  "__glfwPlatformSetTls", referenced from:
      __glfwInputError in libGLFW.a(init.o)
      _glfwInit in libGLFW.a(init.o)
  "__glfwPlatformUnlockMutex", referenced from:
      __glfwInputError in libGLFW.a(init.o)
  "__glfwTerminateNSGL", referenced from:
      __glfwPlatformTerminate in libGLFW.a(cocoa_init.o)
  "__glfwUpdateDisplayLinkDisplayNSGL", referenced from:
      -[GLFWWindowDelegate windowDidChangeScreen:] in libGLFW.a(cocoa_window.o)

我链接到可可、CoreVideo和IOKit框架。知道我遗漏了什么吗?

vfwfrxfs

vfwfrxfs1#

你好可能已经发现了你的错误,而做类似的事情,你忘了链接到几个库是必需的...
“g++ -o测试main.c libGLEW.a libglfw3.a -框架opengl -框架可可-框架IOKit”
来源:https://web.eecs.umich.edu/~sugih/courses/eecs487/glfw-howto/

cmssoen2

cmssoen22#

我有一个类似的问题,你当试图建立GLFW对我自己。它似乎好像当建立GLFW你没有包括所有需要的文件。
构建时,当前版本的GLFW中需要以下macOS特定的文件:

src/cocoa_init.m
src/cocoa_joystick.m
src/cocoa_monitor.m
src/cocoa_window.m
src/cocoa_time.c
src/posix_thread.c
src/nsgl_context.m
src/egl_context.c
src/osmesa_context.c
src/posix_module.c

特别是对于您,请确保包含egl_context.cnsgl_context.mposix_thread.c

相关问题