[Pythonmac-SIG] Building against OpenGL

Chris Barker chris.barker at noaa.gov
Tue Mar 22 16:07:11 EDT 2022


As usual, once you pose the question -- you find the answer.

The trick was not to try to link directly, but rather to use Apple's nifty
"Framework" concept:

extra_link_args.append("-framework OpenGL")

Posting this in case anyone else happens upon it.

-CHB




On Tue, Mar 22, 2022 at 12:47 PM Chris Barker <chris.barker at noaa.gov> wrote:

> I have an app that uses a C (Cython) extension that needs to link against
> the OpenGL libs (libGL and libGLU)
>
> Here's the code that used to work:
>
>     gl_libraries = ["GL", "GLU"]
>
>     ...
>
>     gl_include_dirs.append(
>         "/System/Library/Frameworks/OpenGL.framework/Headers",
>     )
>
> gl_library_dirs.append("/System/Library/Frameworks/OpenGL.framework/Libraries",
>     )
>
> And this resulted in this linking line that fails:
>
> clang -bundle -undefined dynamic_lookup
> -Wl,-rpath,/Users/chris.barker/miniconda3/envs/maproom39/lib
> -L/Users/chris.barker/miniconda3/envs/maproom39/lib
> -Wl,-rpath,/Users/chris.barker/miniconda3/envs/maproom39/lib
> -L/Users/chris.barker/miniconda3/envs/maproom39/lib
> build/temp.macosx-10.9-x86_64-3.9/libmaproom/Tessellator.o
> -L/System/Library/Frameworks/OpenGL.framework/Libraries -lGL -lGLU -o
> build/lib.macosx-10.9-x86_64-3.9/libmaproom/
> Tessellator.cpython-39-darwin.so
> ld: library not found for -lGL
> clang: error: linker command failed with exit code 1 (use -v to see
> invocation)
> error: command '/usr/bin/clang' failed with exit code 1
>
> Some of this makes sense -- as System/Library/Frameworks/OpenGL.framework doesn't
> have Libraries and Headers anymore. However, it also doesn't have the
> headers or libraries (that I can tell) anywhere else in there.
>
> Oddly, the compiler is finding the headers somewhere -- not sure where.
>
> Google has failed me here -- but a few hints:
>
> 1) ctypes had to be updated to find the libs -- that was done, and ctypes
> seems to be working. but what it does is:
>
> In [1]: from ctypes.util import find_library
> In [2]: find_library("OpenGL")
> Out[2]: '/System/Library/Frameworks/OpenGL.framework/OpenGL'
>
> but /System/Library/Frameworks/OpenGL.framework/OpenGL doesn't exist on
> my system at all.
>
> Reading a bit -- it seems that OS-X is doing some kind of cached libs
> trickery -- but how do I tell distutils / clang how to find those libs??
>
> Enclosed is the whole setup.py in case I've missed a detail.
>
> Sometimes Apple Drives me crazy! Thanks for any hints --
>
> -CHB
>
>
>
> --
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R            (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
>
> Chris.Barker at noaa.gov
>


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/pythonmac-sig/attachments/20220322/bca4c049/attachment-0001.html>


More information about the Pythonmac-SIG mailing list