How do you static link to freetype when building eggs?

I've had an ongoing problem building eggs of matplotlib that are statically
linked to freetype. I thought I had it nailed, but evidently I do not. Here
is my script:

export CFLAGS="-arch i386 -I/Developer/src/libpng
-I/Developer/src/freetype/include"
export LDFLAGS="-arch i386 -L/Developer/src/libpng
-L/Developer/src/freetype"
rm -rf build
python setupegg.py bdist_egg

The build of freetype in /Developer/src/freetype does not even have
dynamic libs built. The basedir dict in setupext.py contains the following
entry
for OSX:

'darwin' : []

However, when the resulting egg is installed by users, they still get the
following error:

ImportError: dlopen(/Library/Python/2.5/site-packages/matplotlib-
0.98pre-py2.5-macosx-10.5-i386.egg/matplotlib/ft2font.so, 2):
Library not loaded: /usr/local/lib/libfreetype.6.dylib Referenced from:
/Library/Python/2.5/site-packages/matplotlib-0.98pre-py2.5-macosx-10.5-
i386.egg/matplotlib/ft2font.so Reason: image not found

I thought I had my bases covered -- if anyone has some insight here, please
let me know. maptlotlib is the only missing piece of the "superpack" of
modules that I distribute for OSX.

Chris wrote:

export CFLAGS="-arch i386 -I/Developer/src/libpng -I/Developer/src/freetype/include"
export LDFLAGS="-arch i386 -L/Developer/src/libpng -L/Developer/src/freetype"
rm -rf build
python setupegg.py bdist_egg

The build of freetype in /Developer/src/freetype does not even have dynamic libs built. The basedir dict in setupext.py contains the following entry for OSX:

'darwin' : []

even with that, I think setup.py looks in "standard" places.

ImportError: dlopen(/Library/Python/2.5/site-packages/matplotlib-
0.98pre-py2.5-macosx-10.5-i386.egg/matplotlib/ft2font.so, 2): Library not loaded: /usr/local/lib/libfreetype.6.dylib

Do you have /usr/local/lib/libfreetype.6.dylib on your build system? I assume so, or it wouldn't work at all.

The easiest thing to do is remove it. Not a good solution if you need it for other things, but if nothing else you could temporarily re-name it in your build script, then name it back at end.

Otherwise, poke more into setup.py and setupext.py, and remove any references to /usr/local/lib. Indeed, in an older version of MPL that I have handy, it's added in setupext.py.

An Alternative:

I posted a note about this yesterday, with no replies, so I'll try again:

Instead of all of us going through the pain of figuring out how to build and link static libs for MPL, and PIL, and GDAL, and ???, why don't we just build against the nice Frameworks here:

http://www.kyngchaos.com/wiki/software:frameworks

yes, it's an extra download and install, but it's easy, they can be provided by package distributors, and they can be shared by a bunch of python packages (and other *nix-y software). See my message yesterday for more detail.

I'm doing some testing with PIL -- it's very easy to build, and works fine. It looks like py2app picks up the libs fine, too, though I need a bit more testing.

-Chris

  Referenced from:

···

/Library/Python/2.5/site-packages/matplotlib-0.98pre-py2.5-macosx-10.5-
i386.egg/matplotlib/ft2font.so Reason: image not found

I thought I had my bases covered -- if anyone has some insight here, please
let me know. maptlotlib is the only missing piece of the "superpack" of modules that I distribute for OSX.

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

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

One more comment:

Chris wrote:

maptlotlib is the only missing piece of the "superpack" of
modules that I distribute for OSX.

The Superpack is great, but please, please, please built it Universal -- if you do that, then we'll solve a lot of distribution issues for OS-X python users everywhere. Yes, it's more pain for you, but the Python packages for OS-X situation is just way too ugly -- we really need to make it cleaner.

-Chris

···

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

Hey Chris,

I read your post and perhaps I am missing the obvious, but my basic
question is: apple provides libpng and freetype with xcode which ships
with their computers (an optional install from their cd) and these
work fine with MPL, so why should we require an external dependency?

JDH

···

On Thu, Apr 24, 2008 at 11:51 AM, Christopher Barker <Chris.Barker@...259...> wrote:

I posted a note about this yesterday, with no replies, so I'll try again:

Instead of all of us going through the pain of figuring out how to build
and link static libs for MPL, and PIL, and GDAL, and ???, why don't we
just build against the nice Frameworks here:

http://www.kyngchaos.com/wiki/software:frameworks

yes, it's an extra download and install, but it's easy, they can be
provided by package distributors, and they can be shared by a bunch of
python packages (and other *nix-y software). See my message yesterday
for more detail.

Really?? So I'm an idiot -- I dont deny it.

At any rate, I think I have things working with a static build of both these libraries.

Thanks,
cf

···

On 25/04/2008, at 2:03 PM, John Hunter wrote:

On Thu, Apr 24, 2008 at 11:51 AM, Christopher Barker > <Chris.Barker@...259...> wrote:

I posted a note about this yesterday, with no replies, so I'll try again:

Instead of all of us going through the pain of figuring out how to build
and link static libs for MPL, and PIL, and GDAL, and ???, why don't we
just build against the nice Frameworks here:

http://www.kyngchaos.com/wiki/software:frameworks

yes, it's an extra download and install, but it's easy, they can be
provided by package distributors, and they can be shared by a bunch of
python packages (and other *nix-y software). See my message yesterday
for more detail.

Hey Chris,

I read your post and perhaps I am missing the obvious, but my basic
question is: apple provides libpng and freetype with xcode which ships
with their computers (an optional install from their cd) and these
work fine with MPL, so why should we require an external dependency?

--
Christopher Fonnesbeck
Dunedin, New Zealand
Skype: chrisfonnesbeck

> I read your post and perhaps I am missing the obvious, but my basic
> question is: apple provides libpng and freetype with xcode which ships
> with their computers (an optional install from their cd) and these
> work fine with MPL, so why should we require an external dependency?

Really?? So I'm an idiot -- I dont deny it.

At any rate, I think I have things working with a static build of both
these libraries.

I may have spoken too quickly -- I forgot that on my system in order
to get the mpl build to find the xcode libpng and freetype libs I had
to install pkgconfig, as I described at

http://ipython.scipy.org/moin/Py4Science/InstallationOSX

with the following note:

    matplotlib depends on libpng and freetype, both of which are
provided by the xcode package in
    /usr/X11R6, so I am going to point the mpl build to that
directory. sys.platform is "darwin", so edit
    setupext.py and add '/usr/X11R6' to the "basedir" dictionary for
the 'darwin' key. You need to install
    pkgcong-0.22 from http://pkgconfig.freedesktop.org/releases/ (just
configure, sudo make install it) so that
    matplotlib can use it to find an properly configure png and
freetype. You will need to set the pkgcong path

     > export PKG_CONFIG_PATH=/usr/X11/lib/pkgconfig

so it is not exactly automatic. But it does work, in my experience.

JDH

···

On Thu, Apr 24, 2008 at 9:24 PM, Christopher Fonnesbeck <listservs@...935...> wrote:

John Hunter wrote:

Instead of all of us going through the pain of figuring out how to build
and link static libs for MPL, and PIL, and GDAL, and ???, why don't we
just build against the nice Frameworks here:

http://www.kyngchaos.com/wiki/software:frameworks

I read your post and perhaps I am missing the obvious, but my basic
question is: apple provides libpng and freetype with xcode which ships
with their computers (an optional install from their cd) and these
work fine with MPL, so why should we require an external dependency?

I'd love it if Apple provided this stuff.

Are they static libs? What versions do they ship them with -- I don't have OS-X 10.5, and I don't think I have them -- maybe I need to update XCode.

freetype comes with X11, which is optional (though installed by default on 10.5).

Also, I need libjpeg for PIL, but I guess that's not an OS-X issue.

Here's the goal:

Be able to easily build and distribute binaries of MPL (and other packages that require require similar libs). These binaries should:

   (1) Run on any OS-X 10.4+ system (10.3.9 would be nice too) with python.org's 2.5 framework build.

   (2) Allow packaging up with py2app, to get packages that will run on any 10.4+ system.

As far as I know, the only way to do that now is to statically link against universal builds of all the dependencies that Apple does not provide on a stock 10.4 system. The problem is that there doesn't seem to be any standard source of Universal binaries for any of these libs (and the extra build flags required haven't made it into the source of the host projects). Also, it seems a bit silly to have a whole bunch of different packages all working hard to bundle in the same libs.

I just built PIL against William's Frameworks, and it was oh so easy -- this after spending quite a few hours trying (and not finishing) getting the required libs built as Universal.

We can only use Apple's libs if:
   They provide static Universal versions
or
   The dynamic libs are there on All 10.4+ OS-X boxes.

Maybe we can use more Apple libs for 10.5 only builds.

William has some good comments on this in this thread on the pythonmac list:
  - http://mail.python.org/pipermail/pythonmac-sig/2008-April/019988.html

-Chris

···

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

John Hunter wrote:

I may have spoken too quickly -- I forgot that on my system in order
to get the mpl build to find the xcode libpng and freetype libs I had
to install pkgconfig, as I described at

so it is not exactly automatic. But it does work, in my experience.

The issue here is not that it isn't automatic -- we could fix that -- it's that we can't count on X11 libs being there, particularly on 10.4 systems.

-Chris

···

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