


Solution to the problem when compiling and installing Swoole on Mac that the .h file does not exist
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
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
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
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
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
其中有一句,就是让把这个添加到
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
把这个也添加之前修改过的 .zshrc 文件即可。
接下来就是重头戏了。说白了就是简单的粘贴复制,把 openssl 的文件夹,路径为
/usr/local/Cellar/openssl@1.1/1.1.1h/include/openssl
复制到
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/
目录下即可
至此,第二个问题解决。
然后再运行编译 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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool