【问题标题】:How to make macbook pro recognize GLEW and GLFW?如何让 macbook pro 识别 GLEW 和 GLFW?
【发布时间】:2015-02-24 05:28:39
【问题描述】:

我一般是 macbook 和苹果电脑的新手,所以我很难让 macbook pro 识别 GLEW 和 GLFW。我安装了两个库都没有问题,我的包含如下:glew.h、glxew.h 和 wglew.h 的 /usr/include/GL。 /usr/lib/ 包含 libGLEW.a GLFW 的包含和 lib 文件位于 /usr/local/ 我使用 vim 作为文本编辑器并有一个简单的 main.cpp 程序,但它给了我一个错误,即 glew.h找不到,任何想法为什么会发生这种情况以及我应该如何解决它?

#include <GL/glew.h>

#define GLFW_DLL
#include <GLFW/glfw3.h>

#include <stdio.h>

int main()
{
  if (!glfwInit())
  {
    fprintf (stderr, "ERROR: could not start GLFW\n");
    return 1;
  }

  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
  glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
  glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

  GLFWwindow* window = glfwCreateWindow (640, 480, "Hello Shaders", NULL, NULL);
  if (!window)
  {   fprintf(stderr, "ERROR: could not openwindow with GLFW3\n");
    glgwTerminate();
    return 1;
  }
  glfwMakeContextCurrent (window);

  glewExperimantal = GL_TRUE;
  glewInit();

  const GLubyte* renderer = glGetString(GL_RENDERER);
  const GLubyte* version = glGetString(GL_VERSION);
  printf("Renderer: %s\n", renderer);
  printf("OpenGL version supported %s\n", version);

  glEnable (DEPTH_TEST);
  glDepthFunc (GL_LESS);

  glfwTerminate();

  return 0;
}

我正在编译:

g++ -framework Cocoa -framework OpenGL -framework IOKit -o demo main.cpp -I include -I/sw/include -I/usr/local/include /usr/lib/libGLEW.a /usr/local/lib/libglfw3.a

编辑:将 GL 包括移动到 /usr/local 修复了编译错误,但现在我收到链接器错误,知道可以在这里做什么吗?

Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.10.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 241.9 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -I include -I /sw/include -I /usr/local/include -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/yuri13/Documents/shaders -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.10.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /var/folders/b4/j5zrzg_n7hb205xs22z5f4qc0000gp/T/main-ea70be.o -x c++ main.cpp
clang -cc1 version 6.0 based upon LLVM 3.5svn default target x86_64-apple-darwin14.0.0
ignoring nonexistent directory "include"
ignoring nonexistent directory "/sw/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks (framework directory)
End of search list.
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.10.0 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk -o demo -framework Cocoa -framework OpenGL -framework IOKit /var/folders/b4/j5zrzg_n7hb205xs22z5f4qc0000gp/T/main-ea70be.o /usr/lib/libGLEW.a /usr/local/lib/libglfw3.a -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "_CVDisplayLinkCreateWithCGDisplay", referenced from:
      __glfwPlatformGetVideoModes in libglfw3.a(cocoa_monitor.m.o)
      __glfwPlatformGetVideoMode in libglfw3.a(cocoa_monitor.m.o)
  "_CVDisplayLinkGetNominalOutputVideoRefreshPeriod", referenced from:
      _vidmodeFromCGDisplayMode in libglfw3.a(cocoa_monitor.m.o)
  "_CVDisplayLinkRelease", referenced from:
      __glfwPlatformGetVideoModes in libglfw3.a(cocoa_monitor.m.o)
      __glfwPlatformGetVideoMode in libglfw3.a(cocoa_monitor.m.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

【问题讨论】:

  • -v 添加到g++ 命令行可能会告诉您更多关于它在哪里寻找它的信息。
  • @icktoofay 谢谢,只要我将 GL 包含到 /usr/local/ 中,它就会编译,但现在我得到一个链接器错误,我将在上面的编辑中发布。
  • 我搜了this forum post,说需要加-framework CoreVideo
  • GLEW 在 OS X 上完全没有必要。所有扩展功能都在链接时而不是运行时可用;换句话说,在 OS X 上,当您尝试调用不受支持的扩展时,您会收到 GL_INVALID_OPERATION 错误,而不是为不受支持的函数提供 NULL 指针。实际上,您应该围绕代码中与 GLEW 相关的任何内容编写一些声明 #ifndef __APPLE__ ... #endif
  • @icktoofay 感谢添加 -framework CoreVideo 工作。如果其他人遇到同样的问题,您介意将其作为答案吗?

标签: macos opengl glfw glew


【解决方案1】:

如果您收到与包含头文件相关的错误,则编译器找不到头文件。您可以将-v 标志传递给GCC(包括g++)或Clang(包括clang++)以查看有关它在哪里寻找它的信息。


正如this forum post 解释的那样,如果您收到这些链接错误:

Undefined symbols for architecture x86_64:
  "_CVDisplayLinkCreateWithCGDisplay", referenced from:
      __glfwPlatformGetVideoModes in libglfw3.a(cocoa_monitor.m.o)
      __glfwPlatformGetVideoMode in libglfw3.a(cocoa_monitor.m.o)
  "_CVDisplayLinkGetNominalOutputVideoRefreshPeriod", referenced from:
      _vidmodeFromCGDisplayMode in libglfw3.a(cocoa_monitor.m.o)
  "_CVDisplayLinkRelease", referenced from:
      __glfwPlatformGetVideoModes in libglfw3.a(cocoa_monitor.m.o)
      __glfwPlatformGetVideoMode in libglfw3.a(cocoa_monitor.m.o)
ld: symbol(s) not found for architecture x86_64

那么你可能需要链接CoreVideo 框架。如果是在命令行编译,可以使用-framework CoreVideo

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-03
    • 2021-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多