建筑 C++ 和有什么区别?从 IDE 和命令行生成项目?
从 IDE 和命令行构建项目时,编译器的行为不同,我无法解释。
详细的问题描述比较大,但是很简单。
我有一个 C++ Builder 项目,其中包含一个 PAS 文件 (IncludeUnits.pas)。该 pas 文件列出了多个单元和 inc 文件。这些文件位于单独的文件夹中,并且这些文件夹列在项目选项的库和包含路径中。
文件夹布局:
C:\Demo\Bin
C:\演示\项目
C:\Demo\Project\CBuilder5
C:\Demo\Project\Common
C:\演示\源
C:\Demo\Source\Common
Bin 是输出文件夹,Project/CBuilder5 保存项目(bpr 文件),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 MyProject.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 文件的文件夹中运行这两个命令。并且将路径更改为绝对路径并没有帮助。
将 Test.inc 从 Source\Common 复制到 Source 将会有所帮助。将 {$I Test.inc} 更改为 {$I Common\Test.inc} 也会有帮助。
为什么?看来我错过了一些东西。请记住:项目从 IDE 编译没有问题,无需复制或更改声明即可找到 Test.inc。我是否错过了 make 或 dcc32 的某些切换?
I have different behaviour of compiler, when building project from IDE and from command-line, which I can not explain.
The detailed issue's description is rather big, but it's really simple.
I have a C++ Builder project, which has a PAS-file included (IncludeUnits.pas). This pas-file has several units and inc-files listed. These files are located in separate folders and these folders are listed in library&include paths in project's options.
Folders layout:
C:\Demo\Bin
C:\Demo\Project
C:\Demo\Project\CBuilder5
C:\Demo\Project\Common
C:\Demo\Source
C:\Demo\Source\Common
Bin is output folder, Project/CBuilder5 holds project (bpr-file), Project/Common holds included pas-file (IncludeUnits.pas), Source and Source/Common hold other files (pas&inc). I think that it's pretty usual layout.
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
If I compile this project from C++ Builder IDE - it will compile fine. C++ Builder IDE doesn't have any additional paths in IDE settings set.
Now, I want to compile it from command-line. First, I issue
bpr2mak.exe MyProject.bpr
command.
This command creates MyProject.mak file, where I can see all paths ("....\Source" and "....\Source\Common" are the paths in question):
...
INCLUDEPATH = $(BCB)\include;$(BCB)\include\vcl;..\Common;..\..\Source;..\..\Source\Common
LIBPATH = $(BCB)\lib\obj;$(BCB)\lib;..\Common;..\..\Source;..\..\Source\Common
...
Now, I run make command:
make.exe -B -f"MyProject.mak"
It gives me the following output:
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 Version 13.0 Copyright (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) Fatal: File not found: 'Test.inc'
As you can see - all search path is passed to compiler and the file (Test.inc) is all here - in that Source\Common folder. But still compiler can't find it?
Of course, I run both commands from folder with bpr-file. And changing paths to absolute doesn't help.
Copying Test.inc from Source\Common to Source will help. Changing {$I Test.inc} to {$I Common\Test.inc} will also help.
Why? It seems that I'm missing something. Remember: project have no problems with compiling from IDE, Test.inc is found without copying or changing declaration. Did I miss some switch to make or dcc32?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了原因: dcc32 的命令行缺少 -I 开关,该开关指定包含文件的路径。
由于某种原因,bpr2mak 不尊重此选项。幸运的是,它允许您指定转换 bpr 的备用模板 ->马克。我编辑了默认模板并添加了“-I”选项,将新模板传递给 bpr2mak - 它起作用了。
I found the reason: command line for dcc32 misses -I switch, which specifies paths for include files.
For some reason, bpr2mak doesn't respect this option. Fortunately, it allows you to specify alternate template for conversion bpr -> mak. I edited default template and added "-I" option to it, pass new template to bpr2mak - and it worked.