繁体   English   中英

在Mac OS X Mountain Lion上编译apache2的问题

[英]Problems with compiling apache2 on Mac OS X Mountain Lion

在我的Mac(10.8)上尝试编译最新版本的apache web服务器(2.4.3)时遇到了问题。 当我运行./configure命令时,我得到以下输出:

checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-apple-darwin12.0.0
checking host system type... x86_64-apple-darwin12.0.0
checking target system type... x86_64-apple-darwin12.0.0
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... yes
  setting CC to "/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc"
  setting CPP to "/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc -E"
  setting CFLAGS to " "
  setting CPPFLAGS to " -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK"
  setting LDFLAGS to " "
configure: 
configure: Configuring Apache Portable Runtime Utility library...
configure: 
checking for APR-util... yes
checking for gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc
checking whether the C compiler works... no
configure: error: in `/Users/cti/Downloads/Applications/httpd-2.4.3':
configure: error: C compiler cannot create executables
See `config.log' for more details

以下是日志文件中的最后几行:

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

configure:3056: checking for chosen layout
configure:3058: result: Apache
configure:3861: checking for working mkdir -p
configure:3877: result: yes
configure:3886: checking for grep that handles long lines and -e
configure:3944: result: /usr/bin/grep
configure:3949: checking for egrep
configure:4011: result: /usr/bin/grep -E
configure:4027: checking build system type
configure:4041: result: x86_64-apple-darwin12.0.0
configure:4061: checking host system type
configure:4074: result: x86_64-apple-darwin12.0.0
configure:4094: checking target system type
configure:4107: result: x86_64-apple-darwin12.0.0
configure:4137: 
configure:4139: Configuring Apache Portable Runtime library...
configure:4141: 
configure:4182: checking for APR
configure:4327: result: yes
configure:4587: 
configure:4589: Configuring Apache Portable Runtime Utility library...
configure:4591: 
configure:4628: checking for APR-util
configure:4707: result: yes
configure:4968: checking for gcc
configure:4995: result: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc
configure:5224: checking for C compiler version
configure:5233: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc --version >&5
./configure: line 5235: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc: No such file or directory
configure:5244: $? = 127
configure:5233: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc -v >&5
./configure: line 5235: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc: No such file or directory
configure:5244: $? = 127
configure:5233: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc -V >&5
./configure: line 5235: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc: No such file or directory
configure:5244: $? = 127
configure:5233: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc -qversion >&5
./configure: line 5235: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc: No such file or directory
configure:5244: $? = 127
configure:5264: checking whether the C compiler works
configure:5286: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc    -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK   conftest.c  >&5
./configure: line 5288: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc: No such file or directory
configure:5290: $? = 127
configure:5328: result: no
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.  */
| 
| int
| main ()
| {
| 
|   ;
|   return 0;
| }
configure:5333: error: in `/Users/cti/Downloads/Applications/httpd-2.4.3':
configure:5335: error: C compiler cannot create executables
See `config.log' for more details

正如您在日志输出中看到的那样,./configure中的脚本无法找到我的C编译器的路径,因为它位于/Applications/Xcode.app/Contents/Developer/usr/bin/cc而不是/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc因为它在日志输出中声明你可能会说解决方案很简单我所要做的就是修改配置脚本,对吧? 好吧,问题在于我对shell脚本一无所知,这也是我在过去3个小时里一直在努力的原因。 请帮助。 提前致谢。

我创建和回答的这篇文章中,我只是在努力解决类似的问题所以我想我会分享我的发现。 只需创建符号链接:

# Create a symlink to default Xcode toolchain for OS X lion
sudo ln -s \
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain \
/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain

# Create a symlink to default Xcode toolchain for OS X maverick
sudo ln -s \
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain \
/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain

你应该至少进入下一步。

对于OSX 10.9 Mavericks Apache已经安装,您可以直接转到终端并输入以下命令

查找Apache版本

httpd -v

开始 :

sudo apachectl start 

停止 :

sudo apachectl stop

重新启动 :

sudo apachectl restart

我在OSX Mavericks上并且正在尝试编译Apache 2.2.24并遇到了这个错误。 我从其他答案中看到问题出在apxr上,因此APR返回错误的gcc位置。 Apple提供此功能,Apache配置使用Apple提供的配置。

我突然想到,看到配置脚本有一个选项可以忽略系统提供的APR并使用它自己的APR。

所以我这样做了:

./configure --with-included-apr

它通过了配置步骤并编译没有错误。

checking for gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc accepts -g... yes
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc option to accept ISO C89... none needed
checking how to run the C preprocessor... /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc -E
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc option to accept ISO C99... none needed
checking for pcre-config... false

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

====

我已经下载了pcre-config,运行: ./configure;make;make install

而现在..... Tcharammmm! Httpd apache全装:D

OSX Yosemite (10.10.5)

接受的答案对我有用:

$ cd /Applications/Xcode.app/Contents/Developer/Toolchains

$ ln -s XcodeDefault.xctoolchain/ OSX10.10.xctoolchain
                   ^                      ^
                   |                      |
             existing dir(or file)     link name

(解释为什么在下面工作。)

然后:

httpd-2.4.18$ ./configure  (php may require an additional option)

如果您还要安装php ,则可能需要为./configure添加另一个选项。

在Unix上安装php的基本说明也提供了如何安装apache的说明:

./configure --enable-so
make
make install

Apache的配置帮助说明了这一点:

httpd-2.4.18$ ./configure --help 
...
...
--enable-so    DSO capability. This module will be automatically
               enabled unless you build all modules statically.

这似乎表明--enable-so选项可能是默认选项,但是apache安装说明甚--enable-so没有提到--enable-so 在apache 2.2 docs for configure中 ,我发现了这个:

Modules, disabled by default
Some modules are compiled by default and have to be enabled explicitly...
...
...
--enable-so
...

配置的apache 2.4文档没有提到--enable-so。 相反,他们会告诉你看看输出./configure --helpOptional features ,其中列出了--enable-左右。

因此,我认为您应该像这样配置apache:

 httpd-2.4.18$ ./configure --enable-so

========

安装PHP

为了让mysql与php一起工作,我不得不重新安装php并在php安装文档中更改以下行:

php-7.0.2$ ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql

至:

php-7.0.2$ ./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-pdo-mysql

对于第一个,配置输出表示--with-mysql选项不存在 - 否则php安装正常,apache的htdocs directory中的php文件由php执行。

问题是php已经改变了它的mysql支持,并且不推荐使用mysql_connect() (并从php7中删除),所以现在需要pdo-mysql adapter ,如php文档中所述

重新安装php之后, make install的最后一行表示:

You may want to add: /usr/local/lib/php to your php.ini include_path

php.ini位于: /usr/local/lib/php.ini ,我进行了更改:

include_path = ".:/php/includes:/usr/local/lib/php"

然后我重新启动了apache,确保mysql正在运行,我在浏览器中输入了以下url:

http://localhost:8080/mysql_test.php

我的测试PDO脚本工作(位于/ usr / local / apache2 / htdocs目录中):

<?php

$user = 'root';
$password = ’root_password_here’;
$host = 'localhost';
$dbname = 'my_db';


$pdo = new PDO(
    "mysql:host=$host; dbname=$dbname", 
    $user,
    $password
);

$statement = $pdo->query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = $statement->fetch(PDO::FETCH_ASSOC);
echo htmlentities($row['_message']);

?>

===========

在获得与op相同的错误消息后,我检查了httpd-2.4.18目录中的config.log ,其中的一行说:

./configure: line 5326: /Applications/Xcode.app/Contents/Developer/Toolchains/
OSX10.10.xctoolchain/usr/bin/cc: 
No such file or directory

所以configure脚本正在寻找:

  1. 一个名为的目录:

    /Applications/Xcode.app/Contents/Developer/ Toolchains/OSX10.10.xctoolchain/usr/bin/

  2. 该目录中名为cc的文件。

好的,让我们看看cc是否在该目录中:

~$ cd/Applications/Xcode.app/Contents/Developer/Toolchains/
OSX10.10.xctoolchain/usr/bin/

-bash: cd: /Applications/Xcode.app/Contents/Developer/Toolchains/
OSX10.10.xctoolchain/usr/bin/: No such file or directory

这意味着该目录不存在。 现在你必须弄清楚该长路径中哪个目录不存在:

~$ cd /Applications/Xcode.app
/Applications/Xcode.app$ cd Contents/Developer
/Applications/Xcode.app/Contents/Developer$ cd Toolchains/OSX10.10.xctoolchain

-bash: cd: Toolchains/OSX10.10.xctoolchain/: No such file or directory

/Applications/Xcode.app/Contents/Developer$ cd Toolchains
/Applications/Xcode.app/Contents/Developer/Toolchains$ ls 

XcodeDefault.xctoolchain

您可以看到没有名为OSX10.10.xctoolchain的目录 - 只有一个名为XcodeDefault.xctoolchain的目录。 因此,configure脚本无法在用于查找cc文件的路径中找到目录OSX10.10.xctoolchain 为什么configure查找该目录? 因为编写脚本的开发人员搞砸了或者Apple搞砸了。

configure的真正目标不是找到目录,而是找到讨厌的cc文件。 事实证明cc文件位于:

/Applications/Xcode.app/Contents/Developer/Toolchains/
XcodeDefault.xctoolchain/usr/bin$ ls
...
cc
clang       
...
...

而对于更好奇的:

/Applications/Xcode.app/Contents/Developer/
Toolchains/XcodeDefault.xctoolchain/usr/bin$ ls -al cc

lrwxr-xr-x  1 7stud  admin  5 Oct 29 15:22 cc -> clang

cc只是Xcode的clang编译器的链接。

接受的答案创建了一个从名称OSX10.10.xctoolchain到实际包含cc文件的目录的链接(尽管有几个目录更深) XcodeDefault.xctoolchain

Applications/
  Xcode.app/
    Contents/
      Developer/
        Toolchains/
          XcodeDefault.xctoolchain/
          OSX10.10.xctoolchain/ -> XcodeDefault.xctoolchain/
            usr/
              bin/
                 cc 

换句话说,在创建链接后,有两条路径:

/Applications/Xcode.app/Contents/Developer/Toolchains/
XcodeDefault.xctoolchain/usr/bin

/Applications/Xcode.app/Contents/Developer/Toolchains/
OSX10.10.xctoolchain/usr/bin

将是等同的。 名称XcodeDefault.xctoolchainOSX10.10.xctoolchain将是同一目录的别名。

====

我不明白@AlphaZygma's answer 它建议将以下两个目录添加到PATH(通过/ etc / paths):

/Applications/Xcode.app/Contents/Developer/usr/bin

/Applications/Xcode.app/Contents/Developer/Toolchains/
OSX10.8.xctoolchain/usr/bin
  1. 在我的系统上,第一个目录不包含cc文件,所以我没有理由将该目录添加到我的PATH中。

  2. 第二个目录是配置的目录,说它无法找到。 将不存在的目录添加到PATH仍然意味着它不存在。

  3. 在任何情况下,配置脚本似乎都没有在ccH目录中搜索cc因为错误消息将不存在的路径列为问题。 如何搜索PATH目录会导致列出不存在的路径的错误消息? 配置脚本似乎是从其他地方获取方向,告诉它在哪里搜索cc

  4. 我不确定@AlphaZygma为什么在/etc/paths某些现有路径之间插入新/etc/paths 为什么不在现有路径下添加新路径?

我尝试了几个不同版本的答案,但没有任何对我有用。

====

我查看了./configure --help的输出:

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

...
...

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CPP         C preprocessor

嘿,CC在那里列出。 我们试试吧:

$ ./configure CC=/Applications/Xcode.app/Contents/Developer/
Toolchains/XcodeDefault.xctoolchain/usr/bin/cc

...
...

checking for APR... yes
  setting CPP to "/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.10.xctoolchain/usr/bin/cc -E"
  setting CFLAGS to " "
  setting CPPFLAGS to " -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -DDARWIN_10"
  setting LDFLAGS to " "
configure: 
...
...
configure: error: C compiler cannot create executables

更仔细地看一下输出有这条线:

      setting CPP to "/Applications/Xcode.app/Contents/Developer/Toolchains/
OSX10.10.xctoolchain 

配置脚本仍然提到与CPP一起存在的不存在的路径。 再看一下./configure --help的输出:

Usage: ./configure [OPTION]... [VAR=VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE.  See below for descriptions of some of the useful variables.

...
...

Some influential environment variables:
  CC          C compiler command
  CFLAGS      C compiler flags
  LDFLAGS     linker flags, e.g. -L<lib dir> if you have libraries in a
              nonstandard directory <lib dir>
  LIBS        libraries to pass to the linker, e.g. -l<library>
  CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
              you have headers in a nonstandard directory <include dir>
  CPP         C preprocessor

最后一行列出了错误行中提到的变量CPP。 我们试试吧:

$ ./configure \
> CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc \
> CPP=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc 

...
...

checking how to run the C preprocessor... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
configure: error: in `/Users/7stud/Downloads/httpd-2.4.18':
configure: error: C preprocessor "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc" fails sanity check
See `config.log' for more details

现在错误消息中的所有路径都是正确的,但是“无法进行完整性检查”。 我放弃! 也许别人可以在我离开的地方接我。

好的,感谢这里的建议,以下工作:

$ ./configure \
> CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc \
> CPP='/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -E'

这可以缩短为:

$ ./configure \
> CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc \
> CPP='cc -E'

但随后make失败:

$ make
...
/usr/share/apr-1/build-1/libtool: line 8962: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.10.xctoolchain/usr/bin/cc: No such file or directory

再次提到了不存在的路径 - 这次与libtool一起使用。 那就是我要走那个兔子洞。

在Mac OS X 10.9(Mavericks)上遇到同样的问题; 是的,因为user3097424声明,Apache已预先安装给Mavericks用户,不过对我来说,版本2.2。 因此,需要升级到2.4,就像Adrian Rodriguez所说的那样创建一个符号链接,将'10 .8'替换为'10 .9':

sudo ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain

您可以只添加路径到库路径,而不是创建符号链接,只需使用适当的目录到您的OSX版本。

所以,在你的情况下,它可能看起来像

[user@host ~]$ sudo vi /etc/paths
/usr/bin
/Applications/Xcode.app/Contents/Developer/usr/bin
/Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin
/bin
...

我认为这种方法有点清晰,无需按照不同工具的预期在不同的地方添加符号链接。

无论如何,这只是一个替代解决方案。

希望这可以帮助。

@AlphaZygma这对我很有用。 我在10.8.5并且必须将以下内容添加到/etc/paths

/Applications/Xcode.app/Contents/Developer/usr/bin
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

而不是你的。

完整的解决方案,让我通过:

checking for gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.8.xctoolchain/usr/bin/cc
checking whether the C compiler works... no

问题可以在这里找到: http//mac-dev-env.patrickbougie.com/apache/

命令是(有些需要sudo su):

cd /usr/local/src (mkdir /usr/local/srt if /usr/local/src doesnt exist)
curl --remote-name http://mirror.csclub.uwaterloo.ca/apache/httpd/httpd-2.4.9.tar.gz
tar -xzvf httpd-2.4.9.tar.gz
rmhttpd-2.4.9.tar.gz
cd httpd-2.4.9

sudo xcode-select -switch /
mkdir -p /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin (this might require sudo su)
ln -s /usr/bin/cc /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.9.xctoolchain/usr/bin/cc (this might require sudo su)

./configure --prefix=/usr/local/apache-2.4.9
make
make install

ln -s apache-2.4.9 /usr/local/apache

我刚刚更新到Mavericks并重新创建了我的Web开发环境(包括安装端口)。 我在升级端口时出现此问题:

checking whether the C compiler works... no

我以为我已经完成了所有设置,包括从App Store安装XCode。 但一直有问题。 我能够通过实际运行XCode一次,接受许可协议,并让XCode完全启动来修复它。 下次我尝试升级端口时,我没有收到上面的错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM