Native compilation with Visual Studio fails when depended on shared library has 'nonmatching' sharedLibraryFile and sharedLibraryLinkFile


(Steven Walters) #1

With a project setup similar to the following

libraries {

A {

binaries.withType(SharedLibraryBinary) {

sharedLibraryFile = new File(sharedLibraryFile.parent, ‘A-1.dll’)

}

}

B {} }

sources {

A {}

B {

cpp {

lib libraries.A.shared

}

} }

shared library ‘B’ fails to link with an error of “A.lib can not be found”. The root of this appears to be that the /IMPLIB argument for link is missing when A is being linked to set the .lib file to the expected output file. With the argument missing, Visual Studio is using the standard naming practice of s/.dll/.lib from the DLL to generate the import .lib filepath/name, which is ‘A-1.lib’ here. But when B is linking, it’s using the expected filename of ‘A.lib’ (the default from lack of specifying it in the DSL), which doesn’t exist and thus causes the error.

I’m adding in the following block to force the addition of the /IMPLIB argument as a workaround.

binaries {

withType(SharedLibraryBinary) {

if (toolChain in VisualCpp) {

linker.args “/IMPLIB:${sharedLibraryLinkFile}”

}

} }

Thanks,