Depending on the build type (debug, release) of my main executable, I want to link against the matching builds of my DLLs. What is the correct way to accomplish this using the C++Builder IDE?
Details: I am using Embarcadero C++Builder XE8 (trial, BCC64). My software consists of one executable and multiple libraries (.dll, Dynamic-link Library) loaded during program startup (not at runtime). Each library and executable has its own project and all projects are within the same project group.
To use the compiled libraries in the consuming projects, I have added the import files of the compiled DLLs (.a for BCC64) to the consuming project.
Excerpt from SerialPort.cbproj:
<LibFiles Include="..\..\Win64\Debug\Logger.a" Condition="'$(Platform)'=='Win64'">
<BuildOrder>3</BuildOrder>
<IgnorePath>true</IgnorePath>
</LibFiles>
Unfortunately, the output path for .dll/.a files depends on the variables $(Platform) and $(Config) and therefore the path to those files differs between debug and release builds. The IDE does not(!?) allow me to specify different DLL files to be used for debug and release builds.
I'd rather not resort to ugly hacks like putting the generated binaries for debug and release mode in the same folder just to have a single path to the import files for both builds. The following workaround seems to work, but gets overwritten by C++Builder when saving the project:
<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>
Is there a sane way to solve this problem?
As mentioned on the comments, one possible solution is:
Instead of adding the lib/a files to the project, you can use the
#pragma link
directive in one of your source files to link them. And you can surround it with#ifdef
directives to control which files to link in which conditions, that you can define on the project options.Something like: