lovell/sharp

PKG_CONFIG_PATH and libxml-2.0.pc

onetom opened this issue · 8 comments

I'm getting the following compilation error on Mavericks:

$ npm install sharp

> sharp@0.2.0 install /Users/onetom/XXX/node_modules/sharp
> node-gyp rebuild

Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libxml-2.0', required by 'vips', not found
gyp: Call to 'PKG_CONFIG_PATH="/usr/local/lib/pkgconfig" pkg-config --libs vips' returned exit status 1. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/Cellar/node/0.10.21/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:424:16)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Darwin 13.1.0
gyp ERR! command "node" "/usr/local/Cellar/node/0.10.21/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/onetom/XXX/node_modules/sharp
gyp ERR! node -v v0.10.21
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok
npm ERR! weird error 1
npm ERR! not ok code 0

I had a similar issue with the node-vips library, which I've ended up fixing like this:

↪  cat node_modules/vips/binding.gyp
{
    'targets': [{
        'target_name': 'vips',
        'sources': [
            'src/node-vips.cc',
            'src/transform.cc'
        ],
        'conditions': [
          ['OS=="mac"', {
            'libraries': [
                '<!@(PKG_CONFIG_PATH=/usr/local/Library/ENV/pkgconfig/10.8 pkg-config --libs glib-2.0 vips exiv2)',
            ],
            'include_dirs': [
              '/usr/local/include/glib-2.0',
              '/usr/local/include/vips',
              '/usr/local/include/exiv2',
              '/usr/local/lib/glib-2.0/include'
            ]
          }, {
            'libraries': [
                '<!@(PKG_CONFIG_PATH="/usr/lib/pkgconfig" pkg-config --libs glib-2.0 vips exiv2)'
            ],
            'include_dirs': [
                '/usr/include/glib-2.0',
                '/usr/lib/glib-2.0/include',
                '/usr/lib/x86_64-linux-gnu/glib-2.0/include'
            ],
          }]
        ],
        'cflags': [ '-fexceptions' ],
        'cflags_cc': [ '-fexceptions' ]
    }]
}

I'm very curious how could it compile without tweaks on others' systems.
brew install homebrew/science/vips alone is clearly not enough.

I've got a relatively new 10.9 machine that seems quite happy to compile sharp.cc against the version of vips and its dependencies installed via brew install. It's primarily a development box so I do have all manner of third-party libraries installed.

My best guess is this is either a 10.8 upgraded to 10.9 thing or there are conflicting versions of pkgconfig (homebrew vs native).

I've added the 10.8 pkgconfig path from your node-vips/binding.gyp example to the sharp/bind.gyp as https://gist.github.com/lovell/9496303 - if you're able, please can you replace sharp/binding.gyp locally with this gist and see how node-gyp rebuild responds.

It looks /usr/local/Library/ENV/pkgconfig/10.8/libxml-2.0.pc is put there by homebrew itself, which means there's no harm adding that path to PKG_CONFIG_PATH.

@onetom Please can you verify npm install https://github.com/lovell/sharp/archive/master.tar.gz succeeds on your machine before I publish to npm.

It doesn't work, but if I do a brew link gettext --force, it does.
(I've upgraded my Xcode and everything installed by brew last night,
so my system state is pretty fresh.)

↪  npm install https://github.com/lovell/sharp/archive/master.tar.gz
npm http GET https://github.com/lovell/sharp/archive/master.tar.gz
npm http 200 https://github.com/lovell/sharp/archive/master.tar.gz

> sharp@0.2.1 install /Users/onetom/nix/photo/node_modules/sharp
> node-gyp rebuild

  CXX(target) Release/obj.target/sharp/src/sharp.o
  SOLINK_MODULE(target) Release/sharp.node
ld: library not found for -lintl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Release/sharp.node] Error 1

Thanks for the update @onetom.

If I understand you correctly, the library not found for -lintl error was generated before you then ran brew link gettext --force to use the homebrew-installed version of gettext and libintl.dylib

The gettext formula in homebrew suggests that it can clash with the native Mac OS gettext library. I suspect in your case the compiler is unaware of the native version.

I'll add details of this use of brew link to the README. Thanks again for reporting and helping debug this problem.

Hi @onetom, are there any additional comments or problems relating to this issue before I close it?

Let me check it on another, virgin machine first and I will let you know within a few hours how it went.

Looks perfect, thanks a lot again!

Just for the record:

↪ uname -a
Darwin xxxxx.local 13.1.0 Darwin Kernel Version 13.1.0: Thu Jan 16 19:40:37 PST 2014; root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64

↪ npm install https://github.com/lovell/sharp/archive/master.tar.gz
npm http GET https://github.com/lovell/sharp/archive/master.tar.gz
npm http 200 https://github.com/lovell/sharp/archive/master.tar.gz

sharp@0.2.1 install /Users/*************/node_modules/sharp
node-gyp rebuild

CXX(target) Release/obj.target/sharp/src/sharp.o
SOLINK_MODULE(target) Release/sharp.node
SOLINK_MODULE(target) Release/sharp.node: Finished
sharp@0.2.1 node_modules/sharp