Method One:
- Go to the download page of the MacPorts official website (https://distfiles.macports.org/MacPorts/) Download the pkg file on the Mac system, after the download is complete, double-click, all the Way "next", to the installation press.
- Open a new terminal: Enter sudo port install boost, prompt for a password, enter the password of the account you are currently using (note that the terminal in the password will not have any display prompt, that is, the password will not be displayed), enter, MacPorts will be fully automated download, Install and compile part of the boost library that needs to be compiled separately. The time is a bit long, you can put it to do something else.
- Open Xcode, create a new project, "OS X"-"Application"-"Command line Tool", creating this kind of project.
- Add this precompiled directive to the main file to test # include <boost/asio.hpp>, and you will find that the header file cannot be found. This is because the new project is not configured to use the Boost library. At this point we need to click on "Project Engineering Document"-"Targets"-"buildsetting"-"Search Paths"-"header Search Paths", enter/opt/local/include, so the header file can be found, Add the library file search path, then "Search Paths"-"Library Search Paths", enter/opt/local/lib.
- After adding the header file and library file search directory, click Run, still cannot compile, my side is pop-up error, undefined reference to ' boost::system::system_category (), which may not be connected to the corresponding library, click "Project Project Document"-"Targets"-"Build Phases"-"Link Binary with Libraries", click on the lower side of the + sign, add Libboost_system.a, click Add Another ..., to/ Opt/local/lib Select Libboost_system-mt.a, click on the lower side of the + sign, add Libboost_filesystem.a, click Add Another ..., to/opt/local/ LIB, select Libboost_filesystem-mt.a so that two library files are added.
- I can finally use the Boost library here through these steps, and the ASIO tutorial example on the Boost official website can be programmed.
Install boost open environment on Mac