Home > PHP Framework > Swoole > Solution to the problem when compiling and installing Swoole on Mac that the .h file does not exist

Solution to the problem when compiling and installing Swoole on Mac that the .h file does not exist

谨言慎行
Release: 2020-11-05 16:26:30
Original
2396 people have browsed it

Preface

1. Actually, I really didn’t expect that the installation process would be so Emmm... How to describe it, it’s that kind of thing. In fact, it’s not difficult if you say it’s difficult, but it’s It's also quite disgusting, and there are various problems caused by Mac's native environment and some files not loading automatically.

2. Also, there is really very little information on this kind of question, so record it.


Native environment


And Xcode is not installed.
The local version comes with PHP version 7.3
The local environment configuration tool uses MxSrvs, a Mac version of the PHP development environment. Tool official website: http://www.xsrvs.com/ Although the tool is small, it has all the essentials and is fully sufficient for development.

Key issues

1. The PHP header file cannot be found

2. The Openssl header file cannot be found (the error message is similar to that of PHP)

Preparation work

Official website requirements

Here is one more sentence. Although the official does not marked how many versions of AutoConf need more, it takes 2.68 or above when compiling and installation.

Download the source code package from GitDownload address, what I downloaded is

Installation process

Because it is local, I put the downloaded package directly into the console directory without writing the previous CD directory or the like, and then ran the following code, because I want to compile it into the PHP version in the tool, so The phpzie provided by the tool is used.

/Applications/MxSrvs/bin/php/bin/phpize./configure \--enable-openssl \--enable-http2  \make && sudo make install
Copy after login

Not surprisingly, I encountered problem 1. Neither Baidu nor Bing found anything related to this problem. Then I asked some group friends, and some people said it was because the version was too high. The most suitable version of Swoole is version 7.2.

In the end, the answer that pointed to the essence of the question gave me inspiration. The general answer means that starting from macOs 10.10 and later versions, the PHP version that comes with Mac has canceled some folders, that is to say, since The PHP that comes with it does not have the files required for compilation and installation.

Knowing the reason, it is actually easy to solve. After all, few of our developers use their own environment, so we only need to consider how to dynamically add the PHP version used by the tool to the system environment variable. . Since I have set the system environment variable path before, and I have a little impression, I figured out how to set the environment variable.
In fact, you set the environment variables through .bash_profile

However, after you restart, you need to enter

source ~/.bash_profile
Copy after login
Copy after login

on the command line every time to make it take effect, which is more convenient Trouble, we can use Mac's mechanism to automatically load .zshrc files and add

source ~/.bash_profile
Copy after login
Copy after login

to the end of the file so that manual input is not required every time. To achieve the purpose of dynamically setting environment variables.

At this point, the first problem is solved.

Continue the second installation, and then the second problem occurs. Solving this problem is relatively roundabout.
In fact, the problems encountered are essentially the same. They are all because the software that comes with Mac does not have this .h header file, so these problems occur. The first problem is to bind to the tool. Variables, it is a clever way to change environment variables. Logically speaking, this extension of openssl is used in many places, so it is installed in the overall environment of your own machine.
Before installing openssl, you need to install Xcode first. I did not skip this step. It seems that many environment variables on Mac are linked to the Xcode file directory. It is really disgusting, but it cannot be ignored. After installation, we Then install openssl, enter

brew install openssl
Copy after login


on the command line. If it is detected that yours already exists, you will be prompted to reinstall and run

brew reinstall openssl@1.1
Copy after login


其中有一句,就是让把这个添加到

If you need to have openssl@1.1 first in your PATH run:  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc
Copy after login

把这个也添加之前修改过的 .zshrc 文件即可。
接下来就是重头戏了。说白了就是简单的粘贴复制,把 openssl 的文件夹,路径为

/usr/local/Cellar/openssl@1.1/1.1.1h/include/openssl
Copy after login

复制到

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/
Copy after login

目录下即可
至此,第二个问题解决。

然后再运行编译 Swoole ,等待编译完成就可以了

成果


打完收工!

The above is the detailed content of Solution to the problem when compiling and installing Swoole on Mac that the .h file does not exist. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template