Symbol not found, Expected in: flat namespace

2024/11/18 6:40:12

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 GLenumcdef void glBegin( GLenum mode )

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 **argvcdef 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 WindowglutInit( &argcp, argv )glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE )glutInitWindowPosition( 100, 100 )glutInitWindowSize( 1280, 720 )glutCreateWindow( 'My Shiny New Window' )# Register callbacksglutDisplayFunc( render_scene )# Enter GLUT event processing cycleglutMainLoop()

I also have a setup.py which looks like this:

from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_extsetup(cmdclass = {'build_ext': build_ext},ext_modules = [Extension('window', ['window.pyx'])]
)

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

And I have a window_test.py which looks like this:

import window
window.main()

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: _glBeginReferenced from: /Users/petervaro/cygl/window.soExpected in: flat namespacein /Users/petervaro/cygl/window.so

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

Oh, and I'm on Mac OS X 10.8.5, Cython 19.2 and Python 3.3. Any help will be appreciated!

Thanks in advance!

Answer

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 cythonizeexts = Extension( name='window',sources=['window.pyx'],extra_link_args=['-framework', 'OpenGL', '-framework', 'GLUT'])setup( name='cygl',ext_modules = cythonize( exts ))
https://en.xdnf.cn/q/71091.html

Related Q&A

Why does Django not generate CSRF or Session Cookies behind a Varnish Proxy?

Running Django 1.2.5 on a Linux server with Apache2 and for some reason Django seems like it cannot store CSRF or Session cookies. Therefore when I try to login to the Django admin it gives me a CSRF v…

Shared state with aiohttp web server

My aiohttp webserver uses a global variable that changes over time:from aiohttp import web shared_item = blaasync def handle(request):if items[test] == val:shared_item = doedaprint(shared_item)app =…

ModuleNotFoundError: No module named matplotlib.pyplot

When making a plot, I used both Jupyter Notebook and Pycharm with the same set of code and packages. The code is: import pandas as pd import numpy as np import matplotlib.pyplot as plt # as in Pycha…

python linux - display image with filename as viewer window title

when I display an image with PIL Image it opens an imagemagick window but the title is some gibberish name like tmpWbfj48Bfjf. How do I make the image filename to be the title of the viewer window?

Request body serialization differences when lambda function invoked via API Gateway v Lambda Console

I have a simple API set up in AWS API Gateway. It is set to invoke a Python 2.7 lambda function via API Gateway Proxy integration.I hit a strange error in that the lambda worked (processed the body co…

Determining a homogeneous affine transformation matrix from six points in 3D using Python

I am given the locations of three points:p1 = [1.0, 1.0, 1.0] p2 = [1.0, 2.0, 1.0] p3 = [1.0, 1.0, 2.0]and their transformed counterparts:p1_prime = [2.414213562373094, 5.732050807568877, 0.7320508075…

Split datetime64 column into a date and time column in pandas dataframe

If I have a dataframe with the first column being a datetime64 column. How do I split this column into 2 new columns, a date column and a time column. Here is my data and code so far:DateTime,Actual,Co…

Django - Setting date as date input value

Im trying to set a date as the value of a date input in a form. But, as your may have guessed, its not working.Heres what I have in my template:<div class="form-group"><label for=&qu…

ReduceLROnPlateau gives error with ADAM optimizer

Is it because adam optimizer changes the learning rate by itself. I get an error saying Attempting to use uninitialized value Adam_1/lr I guess there is no point in using ReduceLRonPlateau as Adam wil…

How to make add replies to comments in Django?

Im making my own blog with Django and I already made a Comments system.. I want to add the replies for each comment (like a normal comments box) and I dont know what to do this is my current models.py …