Search code examples
phpbuildcompilationmcrypt

Cannot compile PHP 5.6.17 --with-mcrypt on FreeBSD


I'm trying to build PHP 5.6.17 from source on FreeBSD 10 with libmcrypt-2.5.8 enabled, as per http://php.net/manual/en/mcrypt.requirements.php . The libmcrypt build seems to go OK using make EXTRACFLAGS=-fPIC :

root@dev% dir /usr/local/lib/*mcry*
-rw-r--r--  1 root  wheel  1033370 Jan 14 11:30 /usr/local/lib/libmcrypt.a
-rwxr-xr-x  1 root  wheel      746 Jan 14 11:30 /usr/local/lib/libmcrypt.la

After :

./configure --with-apxs2=/usr/local/apache/bin/apxs \
--with-config-file-path=/usr/local/etc  \
--enable-bcmath --without-cdb \
--with-gd --with-mysql=/usr/local/mysql \
--without-iodbc --enable-inline-optimization \
--without-gdbm --with-ndbm --without-db2 \
--without-dbm --without-readline --without-recode \
--with-openssl --without-db3 --enable-dba \
--with-curl --with-jpeg-dir=/usr/local/lib --enable-calendar \
--with-mhash --enable-mbstring=all --with-png-dir=/usr/local/libpng \
--with-zlib --with-freetype-dir=/usr/local/lib \
--with-pdo-mysql=mysqlnd --enable-exif --with-libxml-dir=/usr/local/lib \
 --enable-zip \
--with-imap=/usr/local/imap-2007f \
--with-mcrypt

Configure output relating to mcrypt:

checking for mcrypt support... yes
checking for libmcrypt version... >= 2.5.6
checking for mcrypt_module_open in -lmcrypt... no
checking for mcrypt_module_open in -lmcrypt... yes

I get this error when I 'make'

    /usr/bin/ld: /usr/local/lib/libmcrypt.a(mcrypt_extra.o): relocation R_X86_64_32 against `mps' can not be used when making a shared object; recompile with -fPIC
    /usr/local/lib/libmcrypt.a: could not read symbols: Bad value
    cc: error: linker command failed with exit code 1 (use -v to see invocation)
    *** Error code 1

    Stop.

make: stopped in /usr/local/dev_build_sources/php-5.6.17

I've previously been able to build using these steps in PHP 5.6.6

This question https://serverfault.com/questions/357020/how-can-i-install-enable-mcrypt-without-re-installing-php suggested making mcrypt (why not libmcrypt?) an extension, but the mcrypt make kept failing

EDIT - adding in result of trying to make the extension in php-5.6.17/ext/mcrypt it seems to fail saying it needs the -fPI flags, but they were already supplied..

root@dev% make EXTRACFLAGS=-fPIC
/bin/sh /usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/libtool --mode=compile cc  -I. -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt -DPHP_ATOM_INC -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/include -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/main -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/local/include  -DHAVE_CONFIG_H  -g -O2   -c /usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/mcrypt.c -o mcrypt.lo
mkdir .libs
 cc -I. -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt -DPHP_ATOM_INC -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/include -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/main -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/mcrypt.c  -fPIC -DPIC -o .libs/mcrypt.o
/bin/sh /usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/libtool --mode=compile cc  -I. -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt -DPHP_ATOM_INC -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/include -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/main -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/local/include  -DHAVE_CONFIG_H  -g -O2   -c /usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/mcrypt_filter.c -o mcrypt_filter.lo
 cc -I. -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt -DPHP_ATOM_INC -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/include -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/main -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/mcrypt_filter.c  -fPIC -DPIC -o .libs/mcrypt_filter.o
/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/mcrypt_filter.c:210:37: warning: passing 'const char *' to
      parameter of type 'char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
        mcrypt_module = mcrypt_module_open(cipher, algo_dir, mode, mode_dir);
                                           ^~~~~~
/usr/local/include/mutils/mcrypt.h:38:34: note: passing argument to parameter 'algorithm' here
        MCRYPT mcrypt_module_open(char *algorithm,
                                        ^
1 warning generated.
/bin/sh /usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/libtool --mode=link cc -DPHP_ATOM_INC -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/include -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/main -I/usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/local/include  -DHAVE_CONFIG_H  -g -O2   -o ./mcrypt.la -export-dynamic -avoid-version -prefer-pic -module -rpath /usr/local/dev_build_sources/TEMP_PHP/php-5.6.17/ext/mcrypt/modules  mcrypt.lo mcrypt_filter.lo -Wl,-rpath,/usr/local/lib -L/usr/local/lib -lmcrypt
cc -shared  .libs/mcrypt.o .libs/mcrypt_filter.o  -L/usr/local/lib /usr/local/lib/libmcrypt.a  -Wl,-rpath -Wl,/usr/local/lib -Wl,-soname -Wl,mcrypt.so -o ./.libs/mcrypt.so
/usr/bin/ld: /usr/local/lib/libmcrypt.a(mcrypt_extra.o): relocation R_X86_64_32 against `mps' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libmcrypt.a: could not read symbols: Bad value
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Solution

  • Got it working:

    In the libmcrypt-2.5.8 source directory

    ./configure --disable-posix-threads --with-pic
    

    Then make without any flags

    PHP build went fine with above configure command and a plain make