簡體   English   中英

符號未找到,預期在:平面命名空間

[英]Symbol not found, Expected in: flat namespace

我有一個巨大的gl.pxd文件,其中包含gl.hglu.hglut.h所有定義。 例如,它有以下這些行:

cdef extern from '<OpenGL/gl.h>':
    ctypedef unsigned int GLenum
    cdef void glBegin( GLenum mode )

我有一個window.pyx文件,如下所示:

# 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調用它並編譯,輸出是這樣的:

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代碼段,我得到了這個錯誤:

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

我的問題與此問題非常類似: 導入Cython生成的.so文件時,此ImportError的含義是什么? - 雖然afaik我沒有外部庫,但我想使用內置的 OpenGL庫...

哦,我使用的是Mac OS X 10.8.5,Cython 19.2和Python 3.3。 任何幫助將不勝感激!

提前致謝!

盡管OpenGL和GLUT在系統上( 內置 )我必須在編譯過程中將它們作為框架鏈接,因此setup.py應如下所示:

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 ))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM