From 909128d2647498b66f4dc6c1e948af6b47d0c42a Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 22 Aug 2018 17:02:41 +0200 Subject: MSVC: Give hint about possible reason for missing import lib If an import lib is unexpectedly not present, the reason is usually that no symbols are exported from the DLL. This is not obvious at all, so catch this condition and explain what is happening. Task-number: QBS-1291 Change-Id: Ia2df8e1a27e0231e855413245703ffc05221722e Reviewed-by: Joerg Bornemann --- share/qbs/modules/cpp/msvc.js | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'share') diff --git a/share/qbs/modules/cpp/msvc.js b/share/qbs/modules/cpp/msvc.js index 698f44398..2e2c28c49 100644 --- a/share/qbs/modules/cpp/msvc.js +++ b/share/qbs/modules/cpp/msvc.js @@ -262,8 +262,8 @@ function collectLibraryDependencies(product) { var seen = {}; var result = []; - function addFilePath(filePath, wholeArchive) { - result.push({ filePath: filePath, wholeArchive: wholeArchive }); + function addFilePath(filePath, wholeArchive, productName) { + result.push({ filePath: filePath, wholeArchive: wholeArchive, productName: productName }); } function addArtifactFilePaths(dep, artifacts) { @@ -271,8 +271,12 @@ function collectLibraryDependencies(product) { return; var artifactFilePaths = artifacts.map(function(a) { return a.filePath; }); var wholeArchive = dep.parameters.cpp && dep.parameters.cpp.linkWholeArchive; - for (var i = 0; i < artifactFilePaths.length; ++i) - addFilePath(artifactFilePaths[i], wholeArchive); + var artifactsAreImportLibs = artifacts.length > 0 + && artifacts[0].fileTags.contains("dynamiclibrary_import"); + for (var i = 0; i < artifactFilePaths.length; ++i) { + addFilePath(artifactFilePaths[i], wholeArchive, + artifactsAreImportLibs ? dep.name : undefined); + } } function addExternalLibs(obj) { @@ -467,6 +471,21 @@ function prepareLinker(project, product, inputs, outputs, input, output) { args = wrapperArgs.concat(args); } var commands = []; + var warningCmd = new JavaScriptCommand(); + warningCmd.silent = true; + warningCmd.libDeps = libDeps; + warningCmd.sourceCode = function() { + for (var i = 0; i < libDeps.length; ++i) { + if (!libDeps[i].productName || File.exists(libDeps[i].filePath)) + continue; + console.warn("Import library '" + FileInfo.toNativeSeparators(libDeps[i].filePath) + + "' does not exist. This typically happens when a DLL does not " + + "export any symbols. Please make sure the '" + libDeps[i].productName + + "' library exports symbols, or, if you do not intend to actually " + + "link against it, specify \"cpp.link: false\" in the Depends item."); + } + }; + commands.push(warningCmd); var cmd = new Command(linkerPath, args) cmd.description = 'linking ' + primaryOutput.fileName; cmd.highlight = 'linker'; -- cgit v1.2.3