问题描述
我有一个巨大的 gl.pxd
文件,所有的定义 gl.h
, glu.h
和 glut.h
。例如它有这些行:
I have a huge gl.pxd
file with all the definitions of gl.h
, glu.h
and glut.h
. For example it has these lines:
cdef extern from '<OpenGL/gl.h>':
ctypedef unsigned int GLenum
cdef void glBegin( GLenum mode )
我有一个 window.pyx
文件,其格式如下:
I have a window.pyx
file, which looks like this:
# Import OpenGL definitions
# headers of gl, glu and glut
from gl cimport *
cdef int argcp
cdef char **argv
cdef void render_scene():
glClear( GL_COLOR_BUFFER_BIT )
glBegin( GL_TRIANGLES )
glVertex2f( -.5, -.5)
glVertex2f( .5, 0 )
glVertex2f( 0, -5. )
glEnd()
glutSwapBuffers()
cpdef main():
# Initialize GLUT and create Window
glutInit( &argcp, argv )
glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE )
glutInitWindowPosition( 100, 100 )
glutInitWindowSize( 1280, 720 )
glutCreateWindow( 'My Shiny New Window' )
# Register callbacks
glutDisplayFunc( render_scene )
# Enter GLUT event processing cycle
glutMainLoop()
我也有一个 setup.py
这个:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
setup(
cmdclass = {'build_ext': build_ext},
ext_modules = [Extension('window', ['window.pyx'])]
)
我用 python3 setup.py build_ext --inplace
并编译,输出是这样:
Which I call with python3 setup.py build_ext --inplace
and it compiles, and the output is this:
running build_ext
cythoning window.pyx to window.c
building 'window' extension
/usr/bin/clang -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -O3 -arch i386 -arch x86_64 -I/Library/Frameworks/Python.framework/Versions/3.3/include/python3.3m -c window.c -o build/temp.macosx-10.6-intel-3.3/window.o
/usr/bin/clang -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -g build/temp.macosx-10.6-intel-3.3/window.o -o /Users/petervaro/cygl/window.so
我有一个 window_test.py
,如下所示:
import window
window.main()
但是如果我想运行这个python代码段,我得到这个错误:
But if I want to run this python snippet I got this error:
Traceback (most recent call last):
File "/Users/petervaro/cygl/window_test.py", line 3, in <module>
import window
ImportError: dlopen(/Users/petervaro/cygl/window.so, 2): Symbol not found: _glBegin
Referenced from: /Users/petervaro/cygl/window.so
Expected in: flat namespace
in /Users/petervaro/cygl/window.so
我的问题真的类似这个:
- 虽然afaik我没有外部库,我想使用内置 OpenGL lib ...
My problem is really similar to this one:What is the meaning of this ImportError when importing a Cython generated .so file? -- although afaik I don't have an external library, I want to use the builtin OpenGL lib...
哦,我在Mac OS X 10.8.5,Cython 19.2和Python 3.3。
任何帮助将不胜感激。
Oh, and I'm on Mac OS X 10.8.5, Cython 19.2 and Python 3.3.Any help will be appreciated!
提前感谢!
推荐答案
即使OpenGL和GLUT在系统上(内建),我必须在编译过程中将它们链接为框架,因此 setup.py
应该看起来像这样:
Even though OpenGL and GLUT are on the system (builtins) I have to link them as frameworks in the compilation process, so the setup.py
should look like this:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
exts = Extension( name='window',
sources=['window.pyx'],
extra_link_args=['-framework', 'OpenGL', '-framework', 'GLUT'])
setup( name='cygl',
ext_modules = cythonize( exts ))
这篇关于未找到符号,预期在:flat命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!