7

I'm not having much success when attempting building pgmagick on OS X Lion with XCode 4.3.1.

I've installed both ImageMagick and GraphicsMagick, along side boost, using the following commands (via homebrew):

$ brew install graphicsmagick --with-magick-plus-plus
$ brew install imagemagick --with-magick-plus-plus
$ brew install boost --with-thread-unsafe

then I'm cloning the repo at https://bitbucket.org/hhatto/pgmagick:

$ hg clone https://bitbucket.org/hhatto/pgmagick/src
$ cd pgmagick
$ python setup.py build

However I always receive the following error:

ld: library not found for -lboost_python
collect2: ld returned 1 exit status

Based on the output on stdout, setup is looking in the right place for the boost (/usr/local/lib).

I've also tried easy_install and pip but with no luck. I'm using Pythonbrew but have also disabled this and tried using the stock python install -- still no success.

Any suggestions on how I can fix the problem, or further diagnose the issue?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Phillip B Oldham
  • 18,807
  • 20
  • 94
  • 134
  • Lion ships with Python 2.7? Try brew edit boost s.t. the bootstrap.sh is called with `--python-version=2.6`. – Paulo Scardine Mar 22 '12 at 13:59
  • @PauloScardine there's nothing in the boost.rb with `--python-version=2.6`. – Phillip B Oldham Mar 22 '12 at 14:08
  • Wait a second: you're doing that as an unprivileged user. Out of curiosity, did your installation targets get thrown into `~/.pythonbrew` by mistake? – MrGomez Mar 23 '12 at 19:52
  • @MrGomez should it matter if it's done as an unprivileged user? **Everything** is done as an unprivileged user, including the installation of boost/graphicsmagick (using homebrew). Trying to build via `sudo` fails also. – Phillip B Oldham Mar 25 '12 at 08:43
  • @unpluggd Yes. To my understanding, `brew` installs to your local user copy (in `~.pythonbrew` by default) unless you tell it otherwise. My only goal here is to ensure your copies of boost and pgmagick are installed in the right directories, since you didn't sudo those in your invocation, and write access to `/usr/local/lib` *should* be locked to root. – MrGomez Mar 25 '12 at 08:55
  • @MrGomez I think you may be misunderstanding the `brew` command. `brew` is the command for `homebrew`, not `pythonbrew`. `homebrew` is a package manager for mac, and has no impact on pythonbrew. `brew install boost` installs into `/usr/local/lib`. – Phillip B Oldham Mar 25 '12 at 10:36
  • @unpluggd Yes, you are correct. Excuse my confusion. – MrGomez Mar 25 '12 at 17:32
  • Here's the problem on my system: check `brew edit boost` to see if `--with-thread-unsafe` is present in your formula file. If it isn't, you'll want to edit the formula to set the threading options [described here](https://github.com/mxcl/homebrew/pull/8928). I noticed that, despite this option not being present in my current formula file, `brew` cheerfully proceeds forward with the install, and I still get `libboost_python-mt` instead of `libboost_python`. If this works for you, I'll write it into an answer. – MrGomez Mar 25 '12 at 20:33

5 Answers5

8

According to my own reproduction of this issue in brew 0.9 and OSX 10.6.8, the problem is --with-thread-unsafe isn't being honored by the current brew formula file. You can verify this by checking the formula with brew edit boost and seeing if the option appears within the contents of the formula.

Because of this, libboost_python-mt.a and libboost_python-mt.dylib are being built instead of libboost_python.a and libboost_python.dylib.

The easiest ways to fix this are to edit your pgmagick setup.py to replace boost_lib="boost_python" with boost_lib="boost_python-mt" (as pointed out here) or to follow the instructions and patch here. It's otherwise a known issue.

Community
  • 1
  • 1
MrGomez
  • 23,788
  • 45
  • 72
  • Rather than touching the `setup.py` file I applied the patch from [github pull request](https://github.com/mxcl/homebrew/pull/8928) which _seems_ to have worked (`import pgmagick` doesn't throw an error, but haven't used it yet). – Phillip B Oldham Mar 27 '12 at 13:21
  • 1
    @unpluggd it should not. The difference here is that thread-unsafe boost got installed through brew, which may only fail those programs which relies on multithread part of boost(all thread-relative op will be replaced w/ no-op). For those programs no needing multithread, both of the versions would be fine. – okm Mar 27 '12 at 13:48
  • 1
    @MrGomez: yes it did, thanks! Though the documentation and usage of pgmagick is dismal (I can't seem to find a way to write to a stream rather than a file) it does actually work. :) – Phillip B Oldham Apr 11 '12 at 14:43
4

The boost_python lib inside /usr/local/lib/ is named after libboost_python-mt.a and libboost_python-mt.dylib, since the default compiling is w/ multi-threads supporting enabled.

Grep boost_lib="boost_python" under ELSE condition in setup.py and replace it w/ boost_lib="boost_python-mt", will fix the "not found" issue.

Also it's OK to ln "-mt" version to libboost_python.a: as described here for linux boost which no longer appends '-mt' suffix since 1.42.

Ignore this line or you could "with-boost-python=boost_python-mt python setup.py install". You could probably append '--with-boost-python=boost_python-mt' to extra_compile_args inside setup.py, to achieve the same goal.

Furthermore, you could install pgmagick through pip in managed envs. Refs http://rohanradio.com/blog/2011/12/02/installing-pgmagick-on-os-x/

Community
  • 1
  • 1
okm
  • 23,575
  • 5
  • 83
  • 90
  • And, as mentioned in the errata: `--with-thread-unsafe` is ignored by the current boost formula file in `brew`. The expected behavior was the generation of `libboost_python.a`, not `libboost_python-mt.a`. Good advice, though! – MrGomez Mar 26 '12 at 20:50
  • 1
    ... although, I tried this procedure on my box, and it didn't work. – MrGomez Mar 26 '12 at 21:00
  • @MrGomez What's the error? I have't tested it on OSX 10.6.8. On 10.7 w/ updated brew, _pgmagick.so was generated and works well. – okm Mar 27 '12 at 01:06
  • It's plausible that this isn't backwards-compatible to 10.6.8. The first invocation clearly upsets Bash (`-bash: with-boost-python=boost_python-mt: command not found`), the second upsets cc1plus with `extra_compile_args=["--with-boost-python=boost_python-mt"]` (`cc1plus: error: unrecognized command line option "-fwith-boost-python=boost_python-mt`). I suppose that's just a thing, since 10.7 is what's actually desired. :) – MrGomez Mar 27 '12 at 01:16
  • @MrGomez That makes sense. Have you tried the first way by replace "boost_python" with "boost_python-mt"? – okm Mar 27 '12 at 02:09
  • Sorry, I missed that. You are correct. Replacing this in pgmagick's setup.py works in 10.6.8, as long as I run it in python2.6. +1. :) – MrGomez Mar 27 '12 at 02:57
2

Note that as of July 2014 the boost Python library is a separate homebrew package called boost-python.

5254f8f510fb30484f8fac8be3d38e388a4392e2
Author: Tim D. Smith <git@tim-smith.us>
Date:   Sat Jul 19 15:37:25 2014 -0700

    Split out Boost.Python

You need to install it separately to get the libboost_python shared library.

mgalgs
  • 15,671
  • 11
  • 61
  • 74
0

I've submitted a pull request to homebrew to build Boost with both mt and non mt (threaded and thread unsafe) binaries which are required to build pgmagick.

Turns out this is a rather common problem, until the patch is accepted, you can check out or use my formula for Boost to build pgmagick.

AndyB
  • 61
  • 2
0

Does setting DYLD_FALLBACK_LIBRARY_PATH=/usr/local/lib in the environment help before the build

e.g

$ export DYLD_FALLBACK_LIBRARY_PATH=/usr/local/lib
$ hg clone https://bitbucket.org/hhatto/pgmagick/src
$ cd pgmagick
$ python setup.py build
Greg Bowyer
  • 1,684
  • 13
  • 14