メメメモモ

プログラミング、筋トレ、ゲーム、etc

新MacBookAirでperlコンパイルエラーが出た

Snow LeopardからLionにアップデートしたiMacでは、コンパイルエラーは起こりませんでした。
新MacBookAirに入っていたLionにて、Xcode4.1をインストールした状態で、perlをコンパイルしたら以下のようなエラーが起こりました。

toke.c:1997:1: warning: use of C99 long long integer constant
toke.c: In function 'Perl_yylex':
toke.c:5516: error: lvalue required as unary '&' operand
toke.c:5516: error: lvalue required as unary '&' operand
toke.c: In function 'S_pending_ident':
toke.c:5755: error: lvalue required as unary '&' operand
toke.c:5755: error: lvalue required as unary '&' operand
toke.c: In function 'S_scan_heredoc':
toke.c:9785: error: invalid operands to binary + (have 'char *' and 'char *')
toke.c:9785: error: lvalue required as unary '&' operand
toke.c:9785: error: lvalue required as unary '&' operand
toke.c: In function 'S_scan_formline':
toke.c:10814: error: invalid operands to binary + (have 'char *' and 'char *')
toke.c:10814: error: lvalue required as unary '&' operand
toke.c:10814: error: lvalue required as unary '&' operand
make: *** [toke.o] Error 1
`sh cflags "optimize='-O3'" toke.o` toke.c
CCCMD = cc -DPERL_CORE -c -fno-common -DPERL_DARWIN -no-cpp-precomp -fno-strict-aliasing -pipe -I/usr/local/include -I/opt/local/include -std=c89 -O3 -Wall -ansi -pedantic -W -Wextra -Wdeclaration-after-statement -Wendif-labels -Wc++-compat -DPERL_GCC_PEDANTIC
toke.c:1997:1: warning: use of C99 long long integer constant
toke.c: In function 'Perl_yylex':
toke.c:5516: error: lvalue required as unary '&' operand
toke.c:5516: error: lvalue required as unary '&' operand
toke.c: In function 'S_pending_ident':
toke.c:5755: error: lvalue required as unary '&' operand
toke.c:5755: error: lvalue required as unary '&' operand
toke.c: In function 'S_scan_heredoc':
toke.c:9785: error: invalid operands to binary + (have 'char *' and 'char *')
toke.c:9785: error: lvalue required as unary '&' operand
toke.c:9785: error: lvalue required as unary '&' operand
toke.c: In function 'S_scan_formline':
toke.c:10814: error: invalid operands to binary + (have 'char *' and 'char *')
toke.c:10814: error: lvalue required as unary '&' operand
toke.c:10814: error: lvalue required as unary '&' operand
make: *** [toke.o] Error 1

このエラーは下記のリンクと同じような現象でした。
https://trac.macports.org/ticket/30032

It looks like the perl Configure script checks for libc functions by doing a symbol dump on libc.dylib. This doesn't work on Lion because they decided to split the functionality of libc into separate dynamic libraries (/usr/lib/system/libsystem_c.dylib, /usr/lib/system/libsystem_kernel.dylib, ...). This means that all of the symbol lookups fail and perl starts trying to use all of it's internal versions of many functions. Because most people on most systems wouldn't actually be using the perl implementations, they aren't compatible with modern compilers. To fix this, I made a little hack to the Configure script to pull in the libc.dylib dependencies to be included in the symbol lookup query.


ということなので、tarballをDLしてきて、リンク先にある「patch-Configure-libc.diff」をConfigureファイルに当てたらコンパイルが通るようになりました。



perlbrewでコンパイルするときは下記のパッチを当てれば解決します。
http://www.perlbrew.pl/FixLion.html

次回のアップデートではパッチがいらなくなるそうです。
ただこのパッチを当てても5.8.9をインストールしようとするとコンパイルエラーが出てしまいます。