Embarcadero C++Builder:可以单独 debug/release DLL 引用吗?
Embarcadero C++Builder: Separate debug/release DLL references possible?
根据我的主要可执行文件的构建类型(调试、发布),我想 link 针对我的 DLL 的匹配构建。使用 C++Builder IDE 完成此操作的正确方法是什么?
详细信息:我正在使用 Embarcadero C++Builder XE8(试用版,BCC64)。我的软件由一个可执行文件和多个库(.dll,Dynamic-link Library)组成,这些库在程序启动期间(不是在运行时)加载。每个库和可执行文件都有自己的项目,所有项目都在同一个项目组中。
为了在消费项目中使用已编译的库,我已将 import files of the compiled DLLs(BCC64 的 .a)添加到消费项目中。
摘自SerialPort.cbproj:
<LibFiles Include="..\..\Win64\Debug\Logger.a" Condition="'$(Platform)'=='Win64'">
<BuildOrder>3</BuildOrder>
<IgnorePath>true</IgnorePath>
</LibFiles>
不幸的是,.dll/.a 文件的输出路径取决于变量 $(Platform) 和 $(Config),因此这些文件的路径在调试版本和发布版本之间有所不同。 IDE 不允许(!?)允许我指定不同的 DLL 文件用于调试和发布版本。
我不想诉诸丑陋的技巧,例如将生成的用于调试和发布模式的二进制文件放在同一个文件夹中,只是为了让两个构建的导入文件有一个单一的路径。
以下解决方法似乎可行,但在保存项目时被 C++Builder 覆盖:
<LibFiles Include="..\..\Win64\Debug\Logger.a" Condition="('$(Platform)'=='Win64') And ('$(Config)'=='Debug')">
<BuildOrder>3</BuildOrder>
<IgnorePath>true</IgnorePath>
</LibFiles>
<LibFiles Include="..\..\Win64\Release\Logger.a" Condition="('$(Platform)'=='Win64') And ('$(Config)'=='Release')">
<BuildOrder>3</BuildOrder>
<IgnorePath>true</IgnorePath>
</LibFiles>
有解决这个问题的明智方法吗?
如评论中所述,一种可能的解决方案是:
您可以在其中一个源文件中使用 #pragma link
指令来 link 它们,而不是将 lib/a 文件添加到项目中。您可以用 #ifdef
指令包围它,以控制在哪些条件下 link 哪些文件,您可以在项目选项中定义这些文件。
类似于:
#ifdef DEBUG
#pragma link "mydebulib.a"
#else
#pragma link "myreleaselib.a"
#endif
Each library and executable has its own project and all projects are within the same project group
我会选择:
#pragma comment(lib, "Logger")
通过这种方式,如果您更改库中的某些内容然后尝试构建可执行文件,C++Builder 会自动重建 Logger.a
(pragma link
不会发生)。
还要考虑在 #pragma link
/ #pragma comment
语句中命名的文件不应包含文件扩展名。编译器将附加适当的: .lib
当目标 Win32
/ .a
然后目标 Win64
.
如前所述,可以在项目选项中指定库路径本身,其中可以使用 $(PLATFORM)
和 $(CONFIG)
。
注意 C++Builder 10.3 Rio Release 2 需要 hotfix or, in some situations, modifying a file in the IDE followed by making or compiling the project would not build the modified file into the resulting binary (see RSP-25525 or the Embarcadero Blog 以获取更多详细信息)。
根据我的主要可执行文件的构建类型(调试、发布),我想 link 针对我的 DLL 的匹配构建。使用 C++Builder IDE 完成此操作的正确方法是什么?
详细信息:我正在使用 Embarcadero C++Builder XE8(试用版,BCC64)。我的软件由一个可执行文件和多个库(.dll,Dynamic-link Library)组成,这些库在程序启动期间(不是在运行时)加载。每个库和可执行文件都有自己的项目,所有项目都在同一个项目组中。
为了在消费项目中使用已编译的库,我已将 import files of the compiled DLLs(BCC64 的 .a)添加到消费项目中。
摘自SerialPort.cbproj:
<LibFiles Include="..\..\Win64\Debug\Logger.a" Condition="'$(Platform)'=='Win64'">
<BuildOrder>3</BuildOrder>
<IgnorePath>true</IgnorePath>
</LibFiles>
不幸的是,.dll/.a 文件的输出路径取决于变量 $(Platform) 和 $(Config),因此这些文件的路径在调试版本和发布版本之间有所不同。 IDE 不允许(!?)允许我指定不同的 DLL 文件用于调试和发布版本。
我不想诉诸丑陋的技巧,例如将生成的用于调试和发布模式的二进制文件放在同一个文件夹中,只是为了让两个构建的导入文件有一个单一的路径。 以下解决方法似乎可行,但在保存项目时被 C++Builder 覆盖:
<LibFiles Include="..\..\Win64\Debug\Logger.a" Condition="('$(Platform)'=='Win64') And ('$(Config)'=='Debug')">
<BuildOrder>3</BuildOrder>
<IgnorePath>true</IgnorePath>
</LibFiles>
<LibFiles Include="..\..\Win64\Release\Logger.a" Condition="('$(Platform)'=='Win64') And ('$(Config)'=='Release')">
<BuildOrder>3</BuildOrder>
<IgnorePath>true</IgnorePath>
</LibFiles>
有解决这个问题的明智方法吗?
如评论中所述,一种可能的解决方案是:
您可以在其中一个源文件中使用 #pragma link
指令来 link 它们,而不是将 lib/a 文件添加到项目中。您可以用 #ifdef
指令包围它,以控制在哪些条件下 link 哪些文件,您可以在项目选项中定义这些文件。
类似于:
#ifdef DEBUG
#pragma link "mydebulib.a"
#else
#pragma link "myreleaselib.a"
#endif
Each library and executable has its own project and all projects are within the same project group
我会选择:
#pragma comment(lib, "Logger")
通过这种方式,如果您更改库中的某些内容然后尝试构建可执行文件,C++Builder 会自动重建 Logger.a
(pragma link
不会发生)。
还要考虑在 #pragma link
/ #pragma comment
语句中命名的文件不应包含文件扩展名。编译器将附加适当的: .lib
当目标 Win32
/ .a
然后目标 Win64
.
如前所述,可以在项目选项中指定库路径本身,其中可以使用 $(PLATFORM)
和 $(CONFIG)
。
注意 C++Builder 10.3 Rio Release 2 需要 hotfix or, in some situations, modifying a file in the IDE followed by making or compiling the project would not build the modified file into the resulting binary (see RSP-25525 or the Embarcadero Blog 以获取更多详细信息)。