I have one project with several prebuilt libraries (static and shared), several static libraries as components and one shared library as a component. Everything compiles, but linking the one shared library fails. This shared library depends on some of the prebuilt and component static libraries, but all the component static libraries are missing from the linker command line. Only the prebuilt libraries are there. What could I be doing wrong? I have added all the neccessary dependencies to the source set of the shared libary component.
Okay, I know I didn’t provide enough info for others to help me, but I finally found my mistake.
I was using a function to configure three PCRE components:
def configurePcrePrebuiltStaticLib(pcreLib, baseDir) {
pcreLib.headers.srcDir "${baseDir}/include"
binaries.withType(StaticLibraryBinary) {
def os = targetPlatform.operatingSystem
def arch = (targetPlatform == platforms.x86) ? "x86" : "x64"
def type = (buildType == buildTypes.debug) ? "d" : ""
def libName = os.windows ?
"${pcreLib.name}${type}.lib" : "lib${pcreLib.name}${type}.a"
staticLibraryFile = file("${baseDir}/lib/${arch}/${libName}")
}
}
I was using this function here:
repositories {
libs(PrebuiltLibraries) {
// ...
pcre {configurePcrePrebuiltStaticLib(it, 'src/3rdParty/pcre-8.37/bin')}
pcrecpp {configurePcrePrebuiltStaticLib(it, 'src/3rdParty/pcre-8.37/bin')}
pcreposix {configurePcrePrebuiltStaticLib(it, 'src/3rdParty/pcre-8.37/bin')}
// ...
}
}
Can you spot my mistake in configurePcrePrebuiltStaticLib
?
I wasn’t just configuring the binaries for these three libs, I was apparently configuring the binaries for all static libs! I should have written pcreLib.
binaries.withType(StaticLibraryBinary) { ...
in the function.