This appendix explains how to acquire and build pdCalc, the program described in this
book.
本附录解释了如何获取和构建pdCalc,即本书中描述的程序。
A.1 Getting the Source Code(获取源代码)
The source code for pdCalc is hosted on Apress’s GitHub repository. The easiest way to find the correct repository is through this book’s Apress website:
http://www.apress.com/us/book/9781484230565
pdCalc的源代码存放在Apress的GitHub仓库中。最简单的方法是是通过本书的Apress网站找到正确的资源库:
http://www.apress.com/us/book/9781484230565
Clicking the Download source code button will take you directly to the GitHubhosted site. Once there, you have two options for downloading the source code. The first option is to use a git client (https://git-scm.com/)) and clone the repository to your local computer. For those familiar with managing source code with git, this is the preferred source code acquisition method. Using git to clone the repository will enable you to pull periodic bug updates from the online repository. Maybe you’ll even decide to contribute a bug fix to pdCalc yourself! The second option for acquiring the source code is to download a single zip file of pdCalc from GitHub. Obviously, downloading a single zip file makes updating the source code significantly more challenging than using git if you have made any local changes.
点击下载源代码按钮将直接带你到GitHub托管的网站。一旦到了那里,你有两个选择来下载源代码。第一个选项是使用git客户端(https://git-scm.com/),将仓库克隆到你的本地电脑上。对于那些熟悉用git管理源代码的人来说,这是首选的源代码获取方法。使用git克隆版本库将使你能够从在线版本库中定期提取错误更新。也许你甚至会决定自己为pdCalc贡献一个错误修复。获得源代码的第二个选择是从GitHub上下载一个单一的pdCalc的压缩文件。很明显,如果你在本地做了任何修改,下载一个单一的压缩文件使得更新源代码比使用git要困难得多。
A.2 Dependencies(依赖)
Now that you have the source code, you’ll probably want to build and execute pdCalc and its unit test suite. Before that can be accomplished, however, you’ll need to ensure that you have an appropriate tool chain. Intentionally, pdCalc requires very few external dependencies, in fact, only two, both of which can be obtained for Linux, Windows, or Mac OS X at no cost. In order to build pdCalc, you will need a modern C++ compiler (C++14 compliant) and Qt (version 4 or 5).
现在你有了源代码,你可能想构建和执行pdCalc及其单元测试套件。然而,在这之前,你需要确保你有一个合适的工具链。有意的是,pdCalc需要很少的外部依赖,事实上,只有两个,这两个都可以在Linux、Windows或者Mac OS X上免费获得。为了构建pdCalc,你需要一个现代的C++编译器(兼容C++14)和Qt(版本4或5)。
As someone willing to have read this book, you probably already have or know how to get a C++ compiler. That said, for simplicity, the build system I provided for pdCalc assumes use of the gcc compiler (mingw in Windows). If you do not have gcc on your Linux system, it should be available through your system’s package manager. If that fails, it can be downloaded from the Free Software Foundation’s website (https://gcc.gnu.org/). On Windows, mingw is bundled with Qt as an optional component. I highly recommend obtaining it through Qt’s installer.
作为愿意读过这本书的人,你可能已经有或者知道如何获得一个C++编译器。也就是说,为了简单起见,我为pdCalc提供的构建系统假设使用gcc编译器(Windows中为mingw)。如果你的Linux系统中没有gcc,它应该可以通过你的系统的包管理器获得。如果没有,可以从自由软件基金会的网站(https://gcc.gnu.org/)下载。在Windows上,mingw作为一个可选的组件与Qt捆绑在一起。我强烈建议通过Qt的安装程序获得它。
On Linux, Qt, including its native integrated development environment (IDE) named Qt Creater, can usually be obtained through the system’s package manager. If you go this route, ensure that you install the development packages for Qt and not just the runtime libraries. For both Linux and Windows, Qt can also be downloaded from http://www.qt.io/download/. Once you are on the website, select the Desktop and Mobile edition, and then choose the version that is licensed appropriately for your use. pdCalc is distributed under the GPL version 3, so the open source edition of Qt is compatible. From Qt’s download page, you can select a fully downloadable binary installer, a network-based binary installer, or the complete source code. Unless you are experienced in building complex libraries from source, I recommend one of the binary installers. On Windows, be sure to install the mingw compiled version of Qt as well as the mingw tool chain. On all operating systems, while not strictly necessary, I highly recommend also installing Qt Creator. Please be patient with the download. Qt, with its many modules, is a powerful, but very sizable package.
在Linux上,Qt,包括其名为Qt Creater的本地集成开发环境(IDE),通常可以通过系统的软件包管理器获得。如果你走这条路,请确保你安装的是Qt的开发包,而不仅仅是运行时库。对于Linux和Windows,Qt也可以从http://www.qt.io/download/。一旦你进入网站,选择桌面版和移动版,然后选择适合你使用的许可版本。pdCalc是在GPL第三版下发布的,所以Qt的开源版是兼容的。从Qt的下载页面,你可以选择一个完全可下载的二进制安装程序,一个基于网络的二进制安装程序,或者完整的源代码。除非你有从源代码构建复杂库的经验,否则我推荐二进制安装程序之一。在Windows上,一定要安装Qt的mingw编译版以及mingw工具链。在所有的操作系统上,虽然不是严格意义上的必须,但我强烈建议同时安装Qt Creator。请耐心等待下载。Qt有许多模块,是一个强大的、但非常有规模的软件包。
A.3 Building pdCalc(构建pdCalc)
To avoid additional dependencies, pdCalc uses qmake for its build system and Qt Test for its unit test framework. Other good alternatives for these tasks are cmake for the build system and any of boost test, cppunit, or Google Test for unit testing. To build pdCalc, you can either configure and compile at the command line or use Qt Creator. Both build methods rely on qmake. Therefore, before discussing how to build pdCalc, a brief explanation of how qmake operates is warranted.
为了避免额外的依赖,pdCalc使用qmake作为它的构建系统,Qt Test作为它的单元测试框架。对于这些任务,其他好的替代方案是用cmake来构建系统,用boost test、cppunit或Google Test来进行单元测试。要构建pdCalc,你可以在命令行中进行配置和编译,或者使用Qt Creator。这两种构建方法都依赖于qmake。因此,在讨论如何构建pdCalc之前,有必要简单解释一下qmake的工作原理。
Using qmake to build a solution is a two-step process involving both qmake and your tool chain’s native make tool. qmake itself does not directly call the compiler and linker. Rather, qmake is simply a cross-platform makefile generator. Therefore, in the first step of the build process, qmake reads project files and produces makefiles native to the tool chain you’re using. This step needs to be performed before the first build and subsequently only after changes requiring modification to project files (e.g., the addition of a new source file). In the second step, the object code is built using your tool chain’s native make tool, which, in turn, calls the compiler and linker. For pdCalc, on a Linux system, you’ll use make, which will, in turn, use gcc for compiling and linking. On a Windows system, you’ll use mingw32-make, which will, in turn, use the mingw compiler and linker.
使用qmake构建解决方案是一个两步过程,涉及到qmake和你的工具链的本地make工具。qmake本身并不直接调用编译器和链接器。相反,qmake只是一个跨平台的makefile生成器。因此,在构建过程的第一步,qmake 读取项目文件并生成你所使用的工具链的本地 makefile。这一步需要在第一次构建之前进行,随后只在需要修改项目文件(例如,增加一个新的源文件)的变化之后进行。在第二步中,使用你的工具链的本地make工具构建目标代码,反过来调用编译器和链接器。对于pdCalc,在Linux系统上,你将使用make,它将反过来使用gcc进行编译和连接。在Windows系统上,你将使用mingw32-make,它将反过来使用mingw编译器和链接器。
Now that you understand how qmake works, let’s examine how to build pdCalc using either Qt Creator or the command line.
现在你已经了解了qmake的工作原理,让我们来看看如何使用Qt Creator或者命令行来构建pdCalc。
A.3.1 Using Qt Creator(使用Qt Creator)
If your preference is to use Qt Creator, most of the complexity of using qmake will be hidden from you. To begin, simply launch the IDE, and open the pdCalc.pro project. This file is located at the top level of the source tree.
如果你倾向于使用Qt Creator,那么使用qmake的大部分复杂性将被隐藏起来。开始时,只需启动IDE,并打开pdCalc.pro项目。这个文件位于源代码树的顶层。
The first time you open a qmake project file with Qt Creator, you will be presented with a configuration list asking you which version of Qt to target. If you only have one version of Qt on your computer, you may only have one option. If you expand the Details button for your selected Qt version, you will be given the option to configure pdCalc for debug, release, and profile and the option to select a folder as your out-of-source build directory. Once you have selected your configuration options, click the Configure Project button. If you need to change your configuration options later, Qt Creator has a tool for that.
当你第一次用Qt Creator打开qmake项目文件时,你会看到一个配置列表,询问你要针对哪个版本的Qt。如果你的电脑上只有一个版本的Qt,你可能只有一个选项。如果你展开你所选择的Qt版本的细节按钮,你会得到配置pdCalc的选项,包括调试、发布和配置文件,以及选择一个文件夹作为你的源外构建目录。一旦你选择了你的配置选项,点击配置项目按钮。如果你以后需要改变你的配置选项,Qt Creator有一个工具可以做到。
After Qt Creator configures your project, you will be presented with the edit mode for the project. The edit mode of Qt Creator is a good tool for exploring the source code. The complete source tree will appear in an expandable tree control on the left side of the display, and individual files can be opened by clicking them. The source tree for pdCalc is described in Appendix B.
在Qt Creator配置好你的项目后,你将看到项目的编辑模式。Qt Creator的编辑模式是一个探索源代码的好工具。完整的源码树将出现在显示屏左侧的可扩展的树形控件中,单个文件可以通过点击它们来打开。pdCalc的源代码树在附录B中描述。
Qt Creator works similarly to any other fully featured IDE you have probably used, and a complete description of its usage is beyond the scope of this Appendix (see http://doc.qt.io/qtcreator/ for the full manual). However, I will highlight a few quick features to help get you started.
Qt Creator的工作原理与你可能使用过的其他全功能IDE类似,对其使用的完整描述超出了本附录的范围(完整的手册见http://doc.qt.io/qtcreator/)。然而,我将强调几个快速功能,以帮助你开始使用。
The first shortcut to learn is choosing which configuration of your project you want to build and run. These options are selected by the monitor icon in the lower left corner of the display. It will currently be labeled with the active project (pdCalc if it’s the only project loaded) and the current configuration (e.g., Debug or Release). If you click this monitor icon, a pane will open allowing you to select which configuration you wish to build and which executable you wish to run. For pdCalc, you’ll have four executable options: pdCalc, pdCalc-simple-cli, pdCalc-simple-gui, and testDriver. pdCalc runs the full version of pdCalc (the GUI by default), pdCalc-simple-cli runs the simple CLI constructed at the end of Chapter 5, pdCalc-simple-gui runs the simple GUI constructed at the end of Chapter 6, and testDriver runs the unit test suite. If you want to change the build or run configuration options, you can click the Projects button (folder icon) on the left side of the display to open the configuration panel. Clicking the Edit button will bring you back to edit mode.
要学习的第一个捷径是选择你要构建和运行的项目的哪个配置。这些选项是由显示屏左下角的监视器图标选择的。它目前会标有活动项目(pdCalc,如果它是唯一加载的项目)和当前配置(例如,调试或发布)。如果你点击这个监视器图标,一个窗格会打开,允许你选择你想建立的配置和你想运行的可执行文件。对于pdCalc,你有四个可执行的选项:pdCalc,pdCalc-simple-cli,pdCalc-simple-gui,以及testDriver。pdCalc运行完整版的pdCalc(默认为GUI),pdCalc-simple-cli运行第五章末尾构建的简单CLI,pdCalc-simple-gui运行第六章末尾的简单GUI,testDriver运行单元测试套件。如果你想改变构建或运行配置选项,你可以点击显示屏左侧的Projects按钮(文件夹图标)来打开配置面板。点击编辑按钮将使你回到编辑模式。
pdCalc can be built either through the Build menu or by clicking the hammer icon (at least that’s what it looks like to me) on the lower left side of the display. If you want to watch the compiler output as it builds, press the Compile Output button on the bottom of your screen. If you have any build issues, they can be found on the Issues tab of the same information panel. Clicking one of these issues should take you to the offending line of source code. Hopefully, pdCalc will build for you with no issues, no warnings, and no errors. If you have build problems, see the “Troubleshooting” section below.
pdCalc可以通过构建菜单或者点击显示屏左下方的锤子图标(至少在我看来是这样的)进行构建。如果你想观察编译器在构建过程中的输出,可以按屏幕下方的编译输出按钮。如果你有任何构建问题,可以在同一信息面板的问题标签上找到。点击这些问题中的一个,你就可以看到有问题的那行源代码了。希望pdCalc在构建时没有问题,没有警告,也没有错误。如果你有构建问题,请参阅下面的“故障排除”部分。
A.3.2 Using the Command Line(使用命令行)
If Qt Creator is not for you, pdCalc can be built directly at the command line. qmake supports out-of-source builds, which is the recommended strategy. Simply create a build directory for each configuration of pdCalc that you wish to build, change your path to the build directory, and issue the following command:
如果Qt Creator不适合你,pdCalc可以直接在命令行中构建。Qmake支持外部构建,这是推荐的策略。只需为您希望构建的pdCalc的每个配置创建一个构建目录,更改构建目录的路径,并发出以下命令:
qmake -recursive CONFIG+=$CONFIG $PATH_TO_PDCALC
where $CONFIG can be replaced by either debug or release (default is debug if the CONFIGoption is not specified) and $PATH_TO_PDCALC should be replaced by the path to pdCalc’s pdCalc.pro file.
其中$CONFIG可以用debug或release代替(如果没有指定CONFIG,默认为debug 选项,而$PATH_TO_PDCALC应该由pdCalc的 pdCalc.pro文件。
The command above triggers qmake to descend the pdCalc directory tree recursively reading each project file and writing a corresponding makefile. If everything executes normally, the output from the above command should be a sequence of lines informing you which project files qmake read. After the makefiles are written, pdCalc can be built by issuing the make command for your system (make on Linux, mingw32-make on Windows) in the same top-level directory from which the qmake command was issued. The code should build cleanly with no warnings or errors.
上面的命令触发了qmake在pdCalc目录树下递归地读取每个项目文件,并写下相应的makefile文件。如果一切执行正常,上述命令的输出应该是一连串的行,告诉你qmake读取了哪些项目文件。在写完makefile后,可以在qmake命令发出的同一顶层目录下执行make命令(Linux的make,Windows的mingw32-make)来构建pdCalc。代码应该能干净地构建,没有警告或错误。
A.4 Executing pdCalc(执行pdCalc)
pdCalc, pdCalc-simple-cli, and pdCalc-simple-gui, and the unit test suite can be executed from Qt Creator, the command line, or by double-clicking the executable (if all of your library paths are correctly set). Let’s look at the details for the first two options. Hopefully, double-clicking is self-explanatory.
pdCalc、pdCalc-simple-cli和pdCalc-simple-gui,以及单元测试套件可以通过Qt Creator、命令行或双击可执行文件来执行(如果你所有的库路径都设置正确的话)。让我们来看看前两个选项的细节。希望双击是不言自明的。
A.4.1 Using Qt Creator(使用Qt Creator)
Using Qt Creator, the currently selected executable can be started by pressing the green triangular run button in the lower left corner. The green triangle with the magnifying glass will start the executable in Qt Creator’s interactive debugger. If the source code is out of date, the project will be built before execution begins. If you currently have the testDriver executable selected, the unit test suite will execute, and its output will appear in the Application Output information panel. Hopefully, you will see details of individual tests passing with a final message of “All tests passed.” If you currently have either the pdCalc or pdCalc-simple-gui executable selected, the GUI should launch. If you have the pdCalc-simple-cli executable selected, the CLI will launch in the Application Output information panel. However, you cannot interact with the CLI using this panel, making this mode of executing the CLI rather useless.
使用Qt Creator,可以通过按下左下角的绿色三角形运行按钮来启动当前选定的可执行文件。带有放大镜的绿色三角形将在Qt Creator的交互式调试器中启动该可执行程序。如果源代码已经过期,项目将在执行开始前被构建。如果你目前选择了testDriver可执行文件,单元测试套件将执行,其输出将出现在应用程序输出信息面板中。希望你能看到个别测试通过的细节,最后的信息是“所有测试通过”。如果你现在选择了pdCalc或者pdCalc-simple-gui的可执行文件,GUI应该启动。如果你选择了pdCalc-simple-cli,CLI将在应用程序输出信息面板中启动。然而,你不能用这个面板与CLI互动,这使得这种执行CLI的模式相当无用。
A.4.2 Using the Command Line(使用命令行)
Due to slight differences in how shared libraries are handled, the Unix (including Linux) and Windows builds target different directories for binaries. On a Unix system, all executables are built in the bin directory and all shared libraries are built in the lib directory. Therefore, pdCalc’s lib directory must be added to the library path before the executables are launched. For example, for a command line execution of pdCalc on Linux, one must first issue the following command:
由于处理共享库的方式略有不同,Unix(包括Linux)和Windows构建的二进制文件的目标目录不同。在Unix系统中,所有的可执行文件都建立在bin目录下,所有的共享库都建立在lib目录下。因此,在启动可执行文件之前,必须将pdCalc的lib目录添加到库路径中。例如,在Linux上用命令行执行pdCalc,必须首先发出以下命令:
export LD_LIBRARY_PATH=$PATH_TO_PDCALC_LIB
where $PATH_TO_PDCALC_LIB is the relative or absolute path to the pdCalc lib directory. As an example, $PATH_TO_PDCALC_LIB can be set to ../lib for the relative path if executing pdCalc from the bin directory.
其中$PATH_TO_PDCALC_LIB是指向pdCalc lib目录的相对或绝对路径。举个例子,如果从bin目录下执行pdCalc,$PATH_TO_PDCALC_LIB的相对路径可以设置为./lib。
Windows does not separate the shared library path from the executable path. This lack of distinction implies that either the lib directory must be added to the main path or that pdCalc’s libraries must reside in the bin directory. I selected the latter option for pdCalc’s build on Windows. That is, both executables and dynamically linked libraries are built directly into the bin directory.
Windows并没有将共享库路径和可执行路径分开。这意味着要么lib目录必须被添加到主路径中,要么pdCalc的库必须位于bin目录中。我为pdCalc在Windows上的构建选择了后者。也就是说,可执行文件和动态链接的库都是直接建立在bin目录下的。
A build of pdCalc creates four executables: pdCalc, pdCalc-simple-cli, pdCalc-simple-gui, and testPdCalc (all have an .exe extension in Windows). testPdCalc runs the unit test suite; it is a command line-only program. As each unit test runs, you will see the names of the individual tests, the passage or failure of each test, and some statistics for each unit test suite. If all of the tests pass, an “All tests passed” message will be issued as the final output.
pdCalc的构建会产生四个可执行文件:pdCalc、pdCalc-simple-cli、pdCalc-simple-gui和testPdCalc(在Windows中都有一个.exe扩展名)。testPdCalc运行单元测试套件;它是一个只用命令行的程序。当每个单元测试运行时,你会看到各个测试的名称,每个测试的通过或失败,以及每个单元测试套件的一些统计数据。如果所有的测试都通过了,“所有的测试都通过了”的消息将作为最后的输出。
The pdCalc executable launches the complete calculator. It can be launched with the —gui option to run the graphical user interface, the —cli option to run the command line interface, or the —batch option to run the calculator in batch mode. Batch operation requires an input file and, optionally, an output file. pdCalc can also be given the —help option to see a listing of the various modes of operation. If no command line option is given, pdCalc defaults to launching the GUI.
pdCalc可执行文件可以启动整个计算器。它可以使用 —gui 选项来运行图形用户界面,使用 —cli 选项来运行命令行界面,或者使用 —batch 选项来以批处理模式运行计算器。批量操作需要一个输入文件,也可以选择一个输出文件。pdCalc还可以使用—help选项来查看各种操作模式的列表。如果没有给出命令行选项,pdCalc默认为启动图形用户界面。
The pdCalc-simple-cli executable launches the simple CLI built at the end of Chapter 5. The pdCalc-simple-gui executable launches the simple GUI built at the end of Chapter 6. Strictly speaking, both of these executables are unnecessary. They are provided merely as a convenience to the reader to be able to run pdCalc before it reaches feature complete status. In agile terms, these feature-incomplete executables provide stages of a minimum viable product.
pdCalc-simple-cli可执行文件可以启动第五章末尾的简单CLI。pdCalc-simple-gui可执行文件可以启动第六章末尾的简单图形用户界面。严格来说,这两个可执行文件都是不必要的。它们只是为了方便读者,在pdCalc达到功能完整状态之前就可以运行。用敏捷的术语来说,这些功能不完整的可执行文件提供了最小可行产品的阶段。
A.5 Troubleshooting(故障排除)
For simplicity, the default qmake project files assume usage of a gcc-based compiler (mingw in Windows). Theoretically, the source code should build without modification on any platform using any C++14-compliant compiler compatible with Qt. Life in the real world never seems to match this ideal. Therefore, some changes to the flags for compiling and linking may be necessary if you choose to use a different compiler. In particular, pdCalc cannot be built by the MSVC compiler provided with Microsoft’s Visual Studio using the default configuration. Additional modifications may also be needed to support exporting names from DLLs using MSVC. If I receive enough reader requests, I may extend the build system to include MSVC in a future update.
为了简单起见,默认的qmake项目文件假定使用基于gcc的编译器(Windows中为mingw)。理论上,源代码应该在任何平台上使用任何与Qt兼容的C++14编译器来编译,而无需修改。现实世界中的生活似乎从未与这一理想相符。因此,如果你选择使用不同的编译器,可能需要对编译和链接的标志进行一些修改。特别是,pdCalc不能由微软Visual Studio提供的MSVC编译器使用默认配置来构建。为了支持使用MSVC从DLLs中导出名称,可能还需要进行额外的修改。如果我收到足够多的读者要求,我可能会在未来的更新中扩展构建系统以包括MSVC。
The above caveat stated, and despite considerable effort to ensure trouble-free building of pdCalc, I still find that every different combination of Qt, gcc, environment variables, operating system, and probably the weather manages to create some new, wonderful build error. If you encounter build or runtime errors, I encourage you to make an effort to diagnose and correct them yourself. Diagnosing and correcting build errors are skills worth acquiring. This will also give you a greater appreciation for the thankless soul on your team tasked with maintaining your cross-platform build system. Often the problem is as trivial as conflicting compiler versions or incorrect/missing paths.
上述注意事项,尽管我做了相当多的努力来确保pdCalc的无故障构建,但我仍然发现Qt、gcc、环境变量、操作系统的不同组合,可能还有其他的原因,都会产生一些新的、奇妙的构建错误。如果你遇到了构建或运行时的错误,我鼓励你努力去诊断和纠正它们。诊断和纠正构建错误是值得掌握的技能。这也会让你对你的团队中负责维护跨平台构建系统的不辞辛劳的灵魂有更多的感激。通常情况下,问题就像编译器版本冲突或不正确/遗漏路径一样微不足道。
In building on Windows, I have found two confounding problems that I will detail now to prevent anyone else from spending inordinate amounts of time debugging them. First, I discovered an obscure qmake Windows-only bug. If you see “Fatal error: MainWindow.moc: No such file or directory” in a Windows release build, congratulations, you found it too. Try changing versions of Qt. The bug appears to be fixed by version 5.9.1.
在Windows上构建时,我发现了两个令人困惑的问题,现在我将详细说明,以防止其他人花过多的时间来调试它们。首先,我发现了一个晦涩的qmake Windows专用的错误。如果你看到“Fatal error: MainWindow.moc: No such file or directory”,恭喜你,你也发现了这个问题。试着改变Qt的版本。这个bug似乎在5.9.1版本中得到了修复。
If you see the error “The system cannot find the file specified” during the building of the hyperbolicLnPlugin, the build has failed to copy the plugins.pdp.win file to the bin directory. This error indicates that mingw32-make has found sh.exe in your path and is building using the sh.exe shell, but qmake has configured your project to use the standard Windows shell, cmd.exe. If you cannot figure out why you have sh.exe in your path, often the culprit is the installation of git. This problem can be fixed by any of the following three different workarounds:
- Remove sh.exe from your path and rebuild. This will cause mingw32-make to correctly build using cmd.exe.
- Manually copy the plugins.pdp.win file to the bin directory, rename it plugins.pdp, delete line 16 (line beginning
win32:QMAKE_PRE_LINK+=
) from hyperbolicLnPlugin.pro, rerun qmake, and then rerun mingw32-make. - Modify line 16 of hyperbolicLnPlugin.pro to use the Unix cp instead of the Windows copy command. To do this, simply replace the line with
win32:QMAKE_PRE_LINK+=cp $$PWD /../plugins.pdp.win $$HOME/bin/plugins.pdp
rerun qmake, and rerun mingw32-make.
如果你在构建hyperbolicLnPlugin的过程中看到错误“The system cannot find the file specified”,说明构建时未能将plugins.pdp.win文件复制到bin目录中。这个错误表明mingw32-make在你的路径中找到了sh.exe,并且正在使用sh.exe shell进行构建,但是qmake已经将你的项目配置为使用标准的Windows shell,cmd.exe。如果你不能弄清楚为什么你的路径中有sh.exe,通常罪魁祸首是git的安装。这个问题可以通过以下三种不同的变通方法来解决:
- 从你的路径中删除sh.exe并重建。这将导致mingw32-make正确地使用cmd.exe进行构建。
- 手动复制plugins.pdp.win文件到bin目录,重命名为plugins.pdp,删除hyperbolicLnPlugin.pro的第16行(以
win32:QMAKE_PRE_LINK+=
开头的行),重新运行qmake,然后再重新运行mingw32-make。 - 修改hyperbolicLnPlugin.pro的第16行,使用Unix的cp而不是Windows的复制命令。要做到这一点,只需用
win32:QMAKE_PRE_LINK+=cp $$PWD /../plugins.pdp.win $$HOME/bin/plugins.pdp
重新运行qmake,然后重新运行mingw32-make。
Finally, I do understand that it can be extremely frustrating to invest time (and possibly money) on a new book and find that you cannot build the accompanying source code per the author’s instructions. If you’ve tried unsuccessfully to fix a build or runtime error yourself and find yourself ready to throw your computer (or this book!) out of the nearest window, just send me an email (PracticalDesignBook@gmail.com). I’ll do my best to get you up and running as quickly and as painlessly as possible.
最后,我明白,在一本新书上投入时间(可能还有金钱),却发现你无法按照作者的指示构建附带的源代码,这可能是非常令人沮丧的。如果你试图自己解决一个构建或运行时的错误而不成功,并且发现自己准备把你的电脑(或这本书!)从最近的窗户扔出去,只要给我发一封电子邮件(PracticalDesignBook@gmail.com)。我会尽我所能让你尽可能快地、无痛苦地启动和运行。