Re: Building against OpenGL
Chris Barker via Pythonmac-SIG <[email protected]> Tue, 22 Mar 2022 13:07:11 -0700
| Newsgroups | gmane.comp.python.apple |
|---|---|
| Message-ID | <CALGmxEJZvO4WAt3BLvT8c4E5qLhknjH3WRZ=3wY9biF6oDsPFQ@mail.gmail.com> |
--===============5718288390284566395==
Content-Type: multipart/alternative; boundary="000000000000b070ce05dad42ac1"
--000000000000b070ce05dad42ac1
Content-Type: text/plain; charset="UTF-8"
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 <[email protected]> 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
>
> [email protected]
>
--
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
[email protected]
--000000000000b070ce05dad42ac1
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">As usual, once you pose the question -- you find the answe=
r.<div><br></div><div>The trick was not to try to link directly, but rather=
to use Apple's nifty "Framework" concept:</div><div><br></di=
v><div>extra_link_args.append("-framework OpenGL")<br></div><div>=
<br></div><div>Posting=C2=A0this in case anyone else happens upon=C2=A0it.<=
/div><div><br></div><div>-CHB</div><div><br></div><div><br></div><div><br><=
/div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_a=
ttr">On Tue, Mar 22, 2022 at 12:47 PM Chris Barker <<a href=3D"mailto:ch=
[email protected]">[email protected]</a>> wrote:<br></div><blockqu=
ote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px=
solid rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr">I have an app th=
at uses a C (Cython) extension that needs to link against the OpenGL libs (=
libGL and libGLU)<div><br></div><div>Here's the code that used to work:=
</div><div><br></div><div><font face=3D"monospace">=C2=A0 =C2=A0 gl_librari=
es =3D ["GL", "GLU"]<br></font></div><div><font face=3D=
"monospace"><br></font></div><div><font face=3D"monospace">=C2=A0 =C2=A0 ..=
.</font></div><div><font face=3D"monospace"><br></font></div><font face=3D"=
monospace">=C2=A0 =C2=A0 gl_include_dirs.append(<br>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 "/System/Library/Frameworks/OpenGL.framework/Headers",<br>=
=C2=A0 =C2=A0 )<br>=C2=A0 =C2=A0 gl_library_dirs.append("/System/Libra=
ry/Frameworks/OpenGL.framework/Libraries",<br>=C2=A0 =C2=A0 )</font><d=
iv><br></div><div>And this resulted in this linking line that fails:</div><=
div><font face=3D"monospace"><br></font></div><div><font face=3D"monospace"=
>clang -bundle -undefined dynamic_lookup -Wl,-rpath,/Users/chris.barker/min=
iconda3/envs/maproom39/lib -L/Users/chris.barker/miniconda3/envs/maproom39/=
lib -Wl,-rpath,/Users/chris.barker/miniconda3/envs/maproom39/lib -L/Users/c=
hris.barker/miniconda3/envs/maproom39/lib build/temp.macosx-10.9-x86_64-3.9=
/libmaproom/Tessellator.o -L/System/Library/Frameworks/OpenGL.framework/Lib=
raries -lGL -lGLU -o build/lib.macosx-10.9-x86_64-3.9/libmaproom/<a href=3D=
"http://Tessellator.cpython-39-darwin.so" target=3D"_blank">Tessellator.cpy=
thon-39-darwin.so</a><br>ld: library not found for -lGL<br>clang: error: li=
nker command failed with exit code 1 (use -v to see invocation)<br>error: c=
ommand '/usr/bin/clang' failed with exit code 1</font><br></div><di=
v><font face=3D"monospace"><br></font></div>Some of this makes sense -- as =
<font face=3D"monospace">System/Library/Frameworks/OpenGL.framework=C2=A0</=
font>doesn't have Libraries and Headers anymore. However, it also doesn=
't have the headers or libraries (that I can tell) anywhere else in the=
re.<br><br><div>Oddly, the compiler is finding the headers somewhere -- not=
sure where.</div><div><br></div><div>Google has failed me here -- but a fe=
w hints:</div><div><br></div><div>1) ctypes had to be updated to find the l=
ibs -- that was done, and ctypes seems to be working. but what it does is:<=
/div><br><font face=3D"monospace">In [1]: from ctypes.util import find_libr=
ary<br>In [2]: find_library("OpenGL")<br>Out[2]: '/System/Lib=
rary/Frameworks/OpenGL.framework/OpenGL'</font><div><br></div><div>but =
<font face=3D"monospace">/System/Library/Frameworks/OpenGL.framework/OpenGL=
doesn't exist on my system at all.</font><br><br>Reading a bit -- it s=
eems that OS-X is doing some kind of cached libs trickery -- but how do I t=
ell distutils=C2=A0/ clang how to find those libs??</div><div><br></div><di=
v>Enclosed is the whole setup.py in case I've missed a detail.</div><di=
v><br></div><div>Sometimes Apple Drives me crazy! Thanks for any hints --=
=C2=A0</div><div><br></div><div>-CHB</div><div><br></div><div><br><br><div>=
<div><div>-- <br><div dir=3D"ltr"><br>Christopher Barker, Ph.D.<br>Oceanogr=
apher<br><br>Emergency Response Division<br>NOAA/NOS/OR&R =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0 =C2=A0(206) 526-6959=C2=A0=C2=A0 voice<br>7600 Sand P=
oint Way NE =C2=A0=C2=A0(206) 526-6329=C2=A0=C2=A0 fax<br>Seattle, WA =C2=
=A098115 =C2=A0 =C2=A0 =C2=A0=C2=A0(206) 526-6317=C2=A0=C2=A0 main receptio=
n<br><br><a href=3D"mailto:[email protected]" target=3D"_blank">Chris.B=
[email protected]</a></div></div></div></div></div></div>
</blockquote></div><br clear=3D"all"><div><br></div>-- <br><div dir=3D"ltr"=
class=3D"gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<b=
r><br>Emergency Response Division<br>NOAA/NOS/OR&R =C2=A0 =C2=A0 =C2=A0=
=C2=A0 =C2=A0 =C2=A0(206) 526-6959=C2=A0=C2=A0 voice<br>7600 Sand Point Wa=
y NE =C2=A0=C2=A0(206) 526-6329=C2=A0=C2=A0 fax<br>Seattle, WA =C2=A098115 =
=C2=A0 =C2=A0 =C2=A0=C2=A0(206) 526-6317=C2=A0=C2=A0 main reception<br><br>=
<a href=3D"mailto:[email protected]" target=3D"_blank">Chris.Barker@noa=
a.gov</a></div>
--000000000000b070ce05dad42ac1--
--===============5718288390284566395==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Pythonmac-SIG maillist - [email protected]
https://mail.python.org/mailman/listinfo/pythonmac-sig
unsubscribe: https://mail.python.org/mailman/options/Pythonmac-SIG
--===============5718288390284566395==--