官术网_书友最值得收藏!

Setting up a Mac-based development platform

One important advantage of using OpenGL is the possibility of cross-compiling the same source code on different platforms. If you are planning to develop your application on a Mac platform, you can easily set up your machine for development using the upcoming steps. We assume that you have either Mac OS X 10.9 or higher installed. OpenGL updates are integrated into the system updates for Mac OS X through the graphics driver.

Installing Xcode and command-line tools

The Xcode development software from Apple provides developers with a comprehensive set of tools, which include an IDE, OpenGL headers, compilers, and debugging tools, to create native Mac applications. To simplify the process, we will compile our code using the command-line interface that shares most of the common features in Linux.

Getting ready

If you are using Mac OS X 10.9 or higher, you can download Xcode through the App Store shipped with Mac OS. Full installation support and instructions are available on the Apple Developer website (https://developer.apple.com/xcode/).

How to do it...

We can install the command-line tools in Xcode through the following steps:

  1. Search for the keyword Terminal in Spotlight and run Terminal.
    How to do it...
  2. Execute the following command in the terminal:
     xcode-select --install
    

    Note that if you have previously installed the command-line tools, an error stating "command-line are already installed" will appear. In this case, simply skip to step 4 to verify the installation.

  3. Click on the Install button to directly install the command-line tools. This will install basic compiling tools such as gcc and make for application development purposes (note that CMake needs to be installed separately).
  4. Finally, enter gcc --version to verify the installation.
    How to do it...

See also

If you encounter the command not found error or other similar issues, make sure that the command-line tools are installed successfully. Apple provides an extensive set of documentation, and more information on installing Xcode can be found at https://developer.apple.com/xcode.

Installing MacPorts and CMake

In this section, we outline the steps to install MacPorts, which greatly simplifies the subsequent setup steps, and CMake for Mac.

Getting ready

Similar to the Windows installation, you can download the binary distribution of CMake from http://www.cmake.org/cmake/resources/software.html and manually configure the command-line options. However, to simplify the installation and automate the configuration process, we highly recommend that you use MacPorts.

How to do it...

To install MacPorts, follow these steps:

  1. Download the MacPorts package installer for the corresponding version of Mac OS X (https://guide.macports.org/#installing.macports):
  2. Double-click on the package installer and follow the onscreen instructions.
    How to do it...
  3. Verify the installation in the terminal by typing in port version, which returns the version of MacPorts currently installed (Version: 2.3.3 in the preceding package).

To install CMake on Mac, follow these steps:

  1. Open the Terminal application.
  2. Execute the following command:
    sudo port install cmake +gui
    

To verify the installation, enter cmake –version to show the current version installed and enter cmake-gui to explore the GUI.

How to do it...

At this point, your Mac is configured for OpenGL development and is ready to compile your first OpenGL application. For those who have been more accustomed to GUIs, using the command-line interface in Mac can initially be an overwhelming experience. However, in the long run, it is a rewarding learning experience due to its overall simplicity. Command-line tools and interfaces are often more time-invariant compared to constantly evolving GUIs. At the end of the day, you can just copy and paste the same command lines, thereby saving precious time needed to consult new documentation every time a GUI changes.

主站蜘蛛池模板: 资溪县| 尼勒克县| 华容县| 顺昌县| 临安市| 福鼎市| 桑日县| 比如县| 德江县| 吉隆县| 万宁市| 长汀县| 大关县| 深圳市| 介休市| 丽江市| 北川| 金阳县| 蕉岭县| 古交市| 阳东县| 延津县| 黔西| 崇左市| 华亭县| 涪陵区| 齐齐哈尔市| 宜城市| 中西区| 凤城市| 海阳市| 井研县| 阿拉善左旗| 文山县| 台东县| 铜山县| 东丽区| 印江| 平罗县| 阿拉善右旗| 尚义县|