【问题标题】:How do you link opengl and glut using waf on osx?如何在 osx 上使用 waf 链接 opengl 和 glut?
【发布时间】:2013-03-10 20:17:46
【问题描述】:

我正在尝试使用 waf 在 osx 上构建一个 C++ opengl 程序,但无法让它工作。

通常当我编译一个 opengl 程序时,我会在终端中使用它:

g++ main.cpp -framework GLUT -framework OpenGL

我使用以下 wscript:

top = '.'
out = 'build'

def options(opt):
    opt.load('compiler_cxx')

def configure(conf):
    conf.load('compiler_cxx')
    # conf.env.append_value('LINKFLAGS', '-framework GLUT -framework OpenGL')

def build(bld):
    bld.program(
      source       = 'main.cpp', 
      target       = 'a',
      linkflags    = ["-framework GLUT", "-framework OpenGL"], 
  )

但是当我构建它时出现链接错误:

$ waf configure
Setting top to                           : /Users/tt/Documents/class/labs/Lab 3 fixed/src 
Setting out to                           : /Users/tt/Documents/class/labs/Lab 3 fixed/src/build 
Checking for 'g++' (c++ compiler)        : /usr/bin/g++ 
'configure' finished successfully (0.040s)
$ waf
Waf: Entering directory `/Users/tt/Documents/class/labs/Lab 3 fixed/src/build'
[2/2] cxxprogram: build/main.cpp.1.o -> build/a
Undefined symbols for architecture x86_64:
"_glViewport", referenced from:
  resize(int, int)in main.cpp.1.o
"_glMatrixMode", referenced from:
  resize(int, int)in main.cpp.1.o
  Camera::show()     in main.cpp.1.o
"_glLoadIdentity", referenced from:
  resize(int, int)in main.cpp.1.o
  Camera::show()     in main.cpp.1.o
"_gluPerspective", referenced from:
  resize(int, int)in main.cpp.1.o
"_glutPostRedisplay", referenced from:
  resize(int, int)in main.cpp.1.o
  idle()    in main.cpp.1.o
"_gluLookAt", referenced from:
  Camera::show()     in main.cpp.1.o
"_glRotatef", referenced from:
  Camera::show()     in main.cpp.1.o
"_glTranslatef", referenced from:
  Camera::show()     in main.cpp.1.o
"_glEnableClientState", referenced from:
  Mesh::render()     in main.cpp.1.o
"_glUseProgram", referenced from:
  Mesh::render()     in main.cpp.1.o
"_glGetAttribLocation", referenced from:
  Mesh::render()     in main.cpp.1.o
"_glEnableVertexAttribArray", referenced from:
  Mesh::render()     in main.cpp.1.o
"_glBindBuffer", referenced from:
  Mesh::render()     in main.cpp.1.o
  Mesh::Mesh(char*)in main.cpp.1.o
"_glVertexPointer", referenced from:
  Mesh::render()     in main.cpp.1.o
"_glVertexAttribPointer", referenced from:
  Mesh::render()     in main.cpp.1.o
"_glNormalPointer", referenced from:
  Mesh::render()     in main.cpp.1.o
"_glDrawElements", referenced from:
  Mesh::render()     in main.cpp.1.o
"_glDisableClientState", referenced from:
  Mesh::render()     in main.cpp.1.o
"_glEnable", referenced from:
  display()    in main.cpp.1.o
"_glClearColor", referenced from:
  display()    in main.cpp.1.o
"_glClear", referenced from:
  display()    in main.cpp.1.o
"_glutSwapBuffers", referenced from:
  display()    in main.cpp.1.o
"_glCreateProgram", referenced from:
  setupGLSL(char*)in main.cpp.1.o
"_glCreateShader", referenced from:
  setupGLSL(char*)in main.cpp.1.o
"_glShaderSource", referenced from:
  setupGLSL(char*)in main.cpp.1.o
"_glCompileShader", referenced from:
  setupGLSL(char*)in main.cpp.1.o
"_glGetShaderiv", referenced from:
  setupGLSL(char*)in main.cpp.1.o
"_glGetShaderInfoLog", referenced from:
  setupGLSL(char*)in main.cpp.1.o
"_glAttachShader", referenced from:
  setupGLSL(char*)in main.cpp.1.o
"_glLinkProgram", referenced from:
  setupGLSL(char*)in main.cpp.1.o
"_glGenBuffers", referenced from:
  Mesh::Mesh(char*)in main.cpp.1.o
"_glBufferData", referenced from:
  Mesh::Mesh(char*)in main.cpp.1.o
"_glutInit", referenced from:
  _main in main.cpp.1.o
"_glutInitDisplayMode", referenced from:
  _main in main.cpp.1.o
"_glutInitWindowSize", referenced from:
  _main in main.cpp.1.o
"_glutCreateWindow", referenced from:
  _main in main.cpp.1.o
"_glutDisplayFunc", referenced from:
  _main in main.cpp.1.o
"_glutIdleFunc", referenced from:
  _main in main.cpp.1.o
"_glutReshapeFunc", referenced from:
  _main in main.cpp.1.o
"_glutKeyboardFunc", referenced from:
  _main in main.cpp.1.o
"_glutKeyboardUpFunc", referenced from:
  _main in main.cpp.1.o
"_glutSpecialFunc", referenced from:
  _main in main.cpp.1.o
"_glutMouseFunc", referenced from:
  _main in main.cpp.1.o
"_glutMotionFunc", referenced from:
  _main in main.cpp.1.o
"_glutMainLoop", referenced from:
  _main in main.cpp.1.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
Waf: Leaving directory `/Users/n7down/Documents/class/spring 2013/5542 (Real Time Rendering)/labs/Lab 3 fixed/src/build'
Build failed
-> task in 'a' failed (exit status 1): 
{task 4537197904: cxxprogram main.cpp.1.o -> a}
['/usr/bin/g++', '-framework GLUT', '-framework OpenGL', 'main.cpp.1.o', '-o', '/Users/tt/Documents/class/labs/Lab 3 fixed/src/build/a']

有没有办法解决/做到这一点?

【问题讨论】:

  • 手动编译会编译吗?
  • 在终端中使用 g++ main.cpp -framework GLUT -framework OpenGL 时没有任何编译或链接错误。
  • 你用的是什么waf版本?

标签: c++ macos opengl glut waf


【解决方案1】:

好吧,您的问题似乎是直接使用 LINKFLAGS 与“-framework X”之类的参数。它将被python错误地解释。直接使用WAF提供的framework参数:

top = '.'
out = 'build'

def options(opt):
    opt.load('compiler_cxx')

def configure(conf):
    conf.load('compiler_cxx')

def build(bld):
    bld.program(
        source       = 'main.cpp', 
        target       = 'a',
        framework    = ["GLUT", "OpenGL"], 
    )

【讨论】:

    猜你喜欢
    • 2013-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-27
    相关资源
    最近更新 更多