Open amz-shahji opened 5 years ago
I can confirm this behavior. It would make sense for Gradle to automatically apply /MTd
to MSVC's arguments when compiling the static debug binary. The workaround I used was to set this flag manually. This worked while building a cpp-application
:
binaries.whenElementFinalized { binary ->
binary.compileTask.get().configure {
if (binary.targetMachine.operatingSystemFamily.windows) {
if (binary.optimized) {
compilerArgs.add("/MT") // static, release linkage
} else {
compilerArgs.add("/MTd") // static, debug linkage
}
}
}
}
Not sure what the preferred workaround is.
@k-mack From my perspective, the test binary.targetMachine.operatingSystemFamily.windows
should be toolChain instanceof VisualCpp
since one can now have clang
, and may be gcc
under Windows
Great point, @zosrothko.
Thanks for the feedback @k-mack. We will see what we can do around default options. Some issues we need to consider when adding defaults is the allowing developers to opt-out of those defaults. Luckily the Provider API keeps evolving and now allow "convention" to be set which can be overwritten. It's a great idea, but still, lack some demonstration and possibly some use case where someone just wants to opt-out one default but not the other one.
Debug libraries generated using default gradle options are incompatible with a default MSVS application project.
Expected Behavior
Generated libraries should be compatible.
Current Behavior
Libraries are incompatible with default options and need tweaking to make them work.
Context
We publish a number of libraries that user can consume in their project. However, the libraries generated using default gradle options are not compatble. When attempted, the linker throws two errors - one related to mismatch _ITERATOR_DEBUG_LEVEL (library is 0 and application is 2) and other related to mismatch of runtime library (library is MT_StaticRelease and app is MTd_StaticDebug).
Steps to Reproduce (for bugs)
P.S. It shouldn't matter but just in case - I am using MSVS 2017 Version 15.6.6 and Gradle v5.0
Workaround
Add _DEBUG macro to the list and utilities project to generate compatible debug libraries.