簡體   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