显示标签为“编译出错”的博文。显示所有博文
显示标签为“编译出错”的博文。显示所有博文

2013年7月26日星期五

[总结] Library not loaded: /opt/local/lib/libiconv.2.dylib 错误解决之法

1. 背景
工作中需要用到 php 的一个图形库的扩展模块 gmagick.
而目前使用的 php 在编译时并没有将 gmagick 静态编译进去,于是通过编译扩展模块来实现.
扩展模块的编译很顺利,但挂在 php 上后发现没有生效.写的简单的脚本测试发现 php error.log 中报如下的错

PHP Warning:  PHP Startup: Unable to load dynamic library '/Users/hy0kl/php/ext/gmagick.so' - dlopen(/Users/hy0kl/php/ext/gmagick.so, 9): Library not loaded: /opt/local/lib/libiconv.2.dylib
  Referenced from: /Users/hy0kl/php/ext/gmagick.so
  Reason: Incompatible library version: gmagick.so requires version 8.0.0 or later, but libiconv.2.dylib provides version 7.0.0 in Unknown on line 0

谷歌后发现,我的机器中有两个版的 libiconv:
$ otool -LD /usr/lib/libiconv.2.dylib
/usr/lib/libiconv.2.dylib:
/usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.0.0)

$ otool -LD /opt/local/lib/libiconv.2.dylib
/opt/local/lib/libiconv.2.dylib:
/opt/local/lib/libiconv.2.dylib (compatibility version 8.0.0, current version 8.1.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
初步确认是动态的加载顺序没有搞对.
多次尝试 + 不断的 google,终于发现了下面的有用帮助:
https://code.google.com/p/git-osx-installer/issues/detail?id=18

Found out that it wasn't a problem running git as root.

I had this in my personal .profile:
export DYLD_LIBRARY_PATH=/usr/lib
export DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib:/sw/lib

Hashed it out and everything was fine..
Don't remember why I put it in there in the first place.. :-/


大家千万不要移除或重命名系统 /usr/lib 下的 libiconv,否则系统报各种问题,生不如死.

2. 解决方法:
$ vi ~/.bashrc

DYLD_LIBRARY_PATH=$HOME/local/lib:/usr/local/lib:/usr/local/mysql/lib
export DYLD_LIBRARY_PATH

DYLD_FALLBACK_LIBRARY_PATH=/opt/local/lib:/usr/lib
export DYLD_FALLBACK_LIBRARY_PATH

加入以后内容,通过小改变一下动态库的扫描路径的先后顺序,即可解决了

2013年7月25日星期四

[转] Building ImageMagick on OSX Lion and can't link libpng

Building ImageMagick on OSX Lion and can't link libpng

Q:
I am trying to build ImageMagick 6.8.0-5 on OSX Lion with support for libpng. I am just using the standard ./configure make make install procedure.
I succeed in compiling when I do not reference libpng.
./configure --with-png=no
make
However, I get an error in make when I try to add libpng support. (libpng-1.5.13)
./configure --with-png=yes
make
The error seems to be a linker error.
/usr/bin/nm: no name list
ld: warning: cannot export hidden symbol _SyncImagePixelCache from magick/.libs/magick_libMagickCore_la-cache.o
ld: warning: cannot export hidden symbol _ResetQuantumState from magick/.libs/magick_libMagickCore_la-quantum.o
Undefined symbols for architecture x86_64:
  "_png_set_check_for_invalid_index", referenced from:
      _WriteOnePNGImage in magick_libMagickCore_la-png.o
      _ReadOnePNGImage in magick_libMagickCore_la-png.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make[1]: *** [magick/libMagickCore.la] Error 1
make: *** [all] Error 2
I have not changed any other options to configure.
How can I fix this to add libpng support?

A:
You'll need to tell ImageMagick where to locate libpng. Luckily, libpng ships with a configuration script entitled "libpng-config".
You can get the link-library option form your local libpng install with the --L_opts flag.
libpng-config --L_opts
This will return something like -L/usr/local/lib. Set ImageMagick's LDFLAGS configuration to match your libpng library.
# Use the returned value for the LDFLAGS
./configure LDFLAGS='-L/usr/local/lib'
If libpng-config returns with a message 'command not found', you'll need to ensure your libpng is installed correctly, and can be located in your shell environment. Often, this can be as simple as adding a custom path to your PATH variable.
export PATH="$PATH:/usr/local/bin"

2013年5月3日星期五

[编译出错] 记一次 XML_Parser 出错的解决


有台机器的 git 有问题,而重新源码编译安装时报如下错:

http-push.c:14:19: error: expat.h: No such file or directory
http-push.c:856: warning: type defaults to ‘int’ in declaration of ‘XML_Char’
http-push.c:856: error: expected ‘;’, ‘,’ or ‘)’ before ‘*’ token
http-push.c: In function ‘lock_remote’:
http-push.c:927: error: ‘XML_Parser’ undeclared (first use in this function)
http-push.c:927: error: (Each undeclared identifier is reported only once
http-push.c:927: error: for each function it appears in.)
http-push.c:927: error: expected ‘;’ before ‘parser’
http-push.c:934: warning: implicit declaration of function ‘XML_SetUserData’
http-push.c:934: error: ‘parser’ undeclared (first use in this function)
http-push.c:935: warning: implicit declaration of function ‘XML_SetElementHandler’
http-push.c:937: warning: implicit declaration of function ‘XML_SetCharacterDataHandler’
http-push.c:937: error: ‘xml_cdata’ undeclared (first use in this function)
http-push.c:938: warning: implicit declaration of function ‘XML_Parse’
http-push.c:943: warning: implicit declaration of function ‘XML_ErrorString’
http-push.c:944: warning: implicit declaration of function ‘XML_GetErrorCode’
http-push.c:947: warning: implicit declaration of function ‘XML_ParserFree’
http-push.c: In function ‘remote_ls’:
http-push.c:1171: error: ‘XML_Parser’ undeclared (first use in this function)
http-push.c:1171: error: expected ‘;’ before ‘parser’
http-push.c:1178: error: ‘parser’ undeclared (first use in this function)
http-push.c:1181: error: ‘xml_cdata’ undeclared (first use in this function)
http-push.c: In function ‘locking_available’:
http-push.c:1245: error: ‘XML_Parser’ undeclared (first use in this function)
http-push.c:1245: error: expected ‘;’ before ‘parser’
http-push.c:1252: error: ‘parser’ undeclared (first use in this function)
make: *** [http-push.o] Error 1

google 了一下说需要安装 XML_Parser http://search.cpan.org/~toddr/XML-Parser-2.41/Parser.pm
下载安装的时候发现,它还依赖 expat http://sourceforge.net/projects/expat/

那就老老实实一步步来吧:
$ cd expat-2.1.0
$ ./configure --prefix=/home/work/local
$ make && make install

$ cd XML-Parser-2.41
$ perl Makefile.PL PREFIX=/home/work/local INSTALLDIRS=perl EXPATLIBPATH=/home/work/local/lib EXPATINCPATH=/home/work/local/include
$ make && make install

$ vi ~/.bashrc 加入新内容

export LD_LIBRARY_PATH=/home/work/local/lib
export C_INCLUDE_PATH=/home/work/local/include
export LIBRARY_PATH=/home/work/local/lib

然后再编译,就没有再报错了.