在本地Mac上编译php-solr失败

时间:2018-06-25 15:56:52

标签: php macos solr

我正在尝试在本地Mac(运行High Sierra)上安装php-solr。

我下载了文件,并能够使用以下文件进行编译:

$ phpize
$ ./configure
$ make && make install

但是随后PHP抱怨由于架构错误而无法加载扩展:

PHP Startup: Unable to load dynamic library '/Applications/AMPPS/php-7.1/lib/extensions/ext/solr.so' - dlopen(/Applications/AMPPS/php-7.1/lib/extensions/ext/solr.so, 9): no suitable image found. Did find: /Applications/AMPPS/php-7.1/lib/extensions/ext/solr.so: mach-o, but wrong architecture /Applications/AMPPS/php-7.1/lib/extensions/ext/solr.so: mach-o, but wrong architecture in Unknown on line 0

我在网上发现了一条提示,说我应该使用它:

./configure CFLAGS="-arch i386 -arch x86_64" LDFLAGS="-arch i386 -arch x86_64" CXXFLAGS="-arch i386 -arch x86_64" --with-php-config=/Applications/AMPPS/php-7.1/bin/php-config --with-curl=/root/custom/software --with-libxml-dir=/root/custom/software

但是当我发出此命令时,终端出现错误:

configure: error: There is something wrong. Please check config.log for more information.

不过,该日志文件并没有告诉我太多。也许你们有个主意吗? (是的,curl和libxml的路径是正确的。)

This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by configure, which was
generated by GNU Autoconf 2.69.  Invocation command line was

  $ ./configure CFLAGS=-arch i386 -arch x86_64 LDFLAGS=-arch i386 -arch x86_64 CXXFLAGS=-arch i386 -arch x86_64 --with-php-config=/Applications/AMPPS/php-7.1/bin/php-config --with-curl=/root/custom/software --with-libxml-dir=/root/custom/software

## --------- ##
## Platform. ##
## --------- ##

hostname = mymac
uname -m = x86_64
uname -r = 17.6.0
uname -s = Darwin
uname -v = Darwin Kernel Version 17.6.0: Tue May  8 15:22:16 PDT 2018; root:xnu-4570.61.1~1/RELEASE_X86_64

/usr/bin/uname -p = i386
/bin/uname -X     = unknown

/bin/arch              = unknown
/usr/bin/arch -k       = unknown
/usr/convex/getsysinfo = unknown
/usr/bin/hostinfo      = Mach kernel version:
     Darwin Kernel Version 17.6.0: Tue May  8 15:22:16 PDT 2018; root:xnu-4570.61.1~1/RELEASE_X86_64
Kernel configured for up to 4 processors.
4 processors are physically available.
4 processors are logically available.
Processor type: x86_64h (Intel x86-64h Haswell)
Processors active: 0 1 2 3
Primary memory available: 16.00 gigabytes
Default processor set: 441 tasks, 1855 threads, 4 processors
Load average: 2.37, Mach factor: 1.83
/bin/machine           = unknown
/usr/bin/oslevel       = unknown
/bin/universe          = unknown

PATH: /Users/myself/.rbenv/shims
PATH: /Users/myself/.rbenv/shims
PATH: /Applications/AMPPS/php-7.0/bin
PATH: /usr/local/bin
PATH: /Library/PostgreSQL/9.6/bin
PATH: /usr/local/bin
PATH: /usr/bin
PATH: /bin
PATH: /usr/sbin
PATH: /sbin
PATH: /opt/ImageMagick/bin
PATH: /Applications/Eclipse-IDE/sdk/platform-tools
PATH: /Applications/Eclipse-IDE/sdk/tools
PATH: /usr/local/Cellar/ant/1.10.3/bin/ant/bin
PATH: /Applications/Eclipse-IDE/sdk/build-tools/22.0.1
PATH: /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/bin
PATH: /Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/bin


## ----------- ##
## Core tests. ##
## ----------- ##

configure:2302: checking for grep that handles long lines and -e
configure:2360: result: /usr/bin/grep
configure:2365: checking for egrep
configure:2427: result: /usr/bin/grep -E
configure:2432: checking for a sed that does not truncate output
configure:2486: result: /usr/bin/sed
configure:2623: checking for cc
configure:2639: found /usr/bin/cc
configure:2650: result: cc
configure:2681: checking for C compiler version
configure:2690: cc --version >&5
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
configure:2701: $? = 0
configure:2690: cc -v >&5
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
configure:2701: $? = 0
configure:2690: cc -V >&5
clang: error: argument to '-V' is missing (expected 1 value)
clang: error: no input files
configure:2701: $? = 1
configure:2690: cc -qversion >&5
clang: error: unknown argument: '-qversion'
clang: error: no input files
configure:2701: $? = 1
configure:2721: checking whether the C compiler works
configure:2743: cc -arch i386 -arch x86_64  -arch i386 -arch x86_64 conftest.c  >&5
configure:2747: $? = 0
configure:2795: result: yes
configure:2798: checking for C compiler default output file name
configure:2800: result: a.out
configure:2806: checking for suffix of executables
configure:2813: cc -o conftest -arch i386 -arch x86_64  -arch i386 -arch x86_64 conftest.c  >&5
configure:2817: $? = 0
configure:2839: result: 
configure:2861: checking whether we are cross compiling
configure:2869: cc -o conftest -arch i386 -arch x86_64  -arch i386 -arch x86_64 conftest.c  >&5
configure:2873: $? = 0
configure:2880: ./conftest
configure:2884: $? = 0
configure:2899: result: no
configure:2904: checking for suffix of object files
configure:2926: cc -c -arch i386 -arch x86_64  conftest.c >&5
configure:2930: $? = 0
configure:2951: result: o
configure:2955: checking whether we are using the GNU C compiler
configure:2974: cc -c -arch i386 -arch x86_64  conftest.c >&5
configure:2974: $? = 0
configure:2983: result: yes
configure:2992: checking whether cc accepts -g
configure:3012: cc -c -g  conftest.c >&5
configure:3012: $? = 0
configure:3053: result: yes
configure:3070: checking for cc option to accept ISO C89
configure:3133: cc  -c -arch i386 -arch x86_64  conftest.c >&5
configure:3133: $? = 0
configure:3146: result: none needed
configure:3172: checking how to run the C preprocessor
configure:3203: cc -E  conftest.c
configure:3203: $? = 0
configure:3217: cc -E  conftest.c
conftest.c:9:10: fatal error: 'ac_nonexistent.h' file not found
#include <ac_nonexistent.h>
         ^~~~~~~~~~~~~~~~~~
1 error generated.
configure:3217: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
| #include <ac_nonexistent.h>
configure:3242: result: cc -E
configure:3262: cc -E  conftest.c
configure:3262: $? = 0
configure:3276: cc -E  conftest.c
conftest.c:9:10: fatal error: 'ac_nonexistent.h' file not found
#include <ac_nonexistent.h>
         ^~~~~~~~~~~~~~~~~~
1 error generated.
configure:3276: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
| #include <ac_nonexistent.h>
configure:3307: checking for icc

此行似乎会产生错误:

conftest.c:9:10: fatal error: 'ac_nonexistent.h' file not found

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

经过大量的反复试验,我开始使用它。

我对编译器的标志处在正确的位置,但最终使用了这些标志:

CC="gcc -arch i386" CXX="g++ -arch i386"

此外,我需要Solr扩展与AMPPS兼容。所以整个过程看起来像这样(如果有人偶然发现):

cd into the downloaded solr-folder

/Applications/AMPPS/php-7.1/bin/phpize

./configure --with-php-config=/Applications/AMPPS/php-7.1/bin/php-config --with-curl=/Applications/AMPPS/extra  --with-libxml-dir=/Applications/AMPPS/extra CC="gcc -arch i386" CXX="g++ -arch i386"

make && make install (you might need to sudo this)