从 IDE 和命令行构建项目时,我有不同的编译器行为,我无法解释。
详细问题的描述相当大,但它真的很简单。
我有一个 C++ Builder 项目,其中包含一个 PAS 文件(IncludeUnits.pas)。这个 pas 文件列出了几个单位和 inc 文件。这些文件位于单独的文件夹中,这些文件夹列在项目选项中的库和包含路径中。
文件夹布局:
C:\Demo\Bin
C:\Demo\Project
C:\Demo\Project\CBuilder5
C:\Demo\Project\Common
C:\Demo\Source
C:\Demo\Source\Common
Bin 是输出文件夹,Project/CBuilder5 保存项目(bpr-file),Project/Common 保存包含的 pas 文件(IncludeUnits.pas),Source 和 Source/Common 保存其他文件(pas&inc)。我认为这是非常常见的布局。
C:\Demo\Project\Common\ IncludeUnits.pas:
unit IncludeUnits;
interface
uses
Test;
implementation
end.
C:\Demo\Source\ Test.pas:
unit Test;
interface
{$I Test.inc}
implementation
end.
C:\Demo\Source\Common\ Test.inc:
// this file is empty
如果我从 C++ Builder IDE 编译这个项目 - 它会编译得很好。C++ Builder IDE 在 IDE 设置集中没有任何额外的路径。
现在,我想从命令行编译它。首先,我发出
bpr2mak.exe 我的项目.bpr
命令。
此命令创建 MyProject.mak 文件,我可以在其中看到所有路径(“....\Source”和“....\Source\Common”是有问题的路径):
...
INCLUDEPATH = $(BCB)\include;$(BCB)\include\vcl;..\Common;..\..\Source;..\..\Source\Common
LIBPATH = $(BCB)\ lib\obj;$(BCB)\lib;..\Common;..\..\Source;..\..\Source\Common
...
现在,我运行 make 命令:
make.exe -B -f"MyProject.mak"
它给了我以下输出:
C:\PROGRA~1\Borland\CBUILD~2\BIN\dcc32 -N2....\Bin -N0....\Bin -$Y+ -$W -$R -v -JPHNE -M -UC: \PROGRA~1\Borland\CBUILD~2\bin..\include;C:\PROGRA~1\Borland\CBUILD~2\bin..\include\vcl;..\Common;..\..\Source ;..\..\Source\Common -D_DEBUG;_RTLDLL;NO_STRICT -OC:\PROGRA~1\Borland\CBUILD~2\bin..\include;C:\PROGRA~1\Borland\CBUILD~2\bin ..\include\vcl;..\Common;..\..\Source;..\..\Source\Common --BCB ..\Common\IncludeUnits.PAS
Borland Delphi 版本 13.0 版权所有 (c) 1983, 99 Inprise Corporation
C:\Demo\Project\Common\IncludeUnits.pas(1) C:\Demo\Project\Common\IncludeUnits.pas(1) C:\Demo\Project\Common\IncludeUnits.pas(1) C: \Demo\Project\Common\IncludeUnits.pas(6) C:\Demo\Source\Test.pas(1) C:\Demo\Source\Test.pas(5) 致命:找不到文件:'Test.inc'
如您所见 - 所有搜索路径都传递给编译器,文件 (Test.inc) 都在这里 - 在 Source\Common 文件夹中。但是编译器仍然找不到它?
当然,我从带有 bpr-file 的文件夹中运行这两个命令。将路径更改为绝对路径也无济于事。
将 Test.inc 从 Source\Common 复制到 Source会有所帮助。将 {$I Test.inc} 更改为 {$I Common\Test.inc}也会有所帮助。
为什么?看来我错过了什么。请记住:从 IDE 编译项目没有问题,没有复制或更改声明即可找到 Test.inc。我错过了make或dcc32的一些开关吗?