From b44ff4ec7d2c2458aab04b5daf79134e5d284f6e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 19 Mar 2018 06:39:00 +0100 Subject: Fix compile error when having dependency on static library that has dependency on dynamic libraries Static libraries need to be defined before dynamic libraries when building executable, otherwise you get linking error --- backend/ninja/Ninja.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'backend/ninja') diff --git a/backend/ninja/Ninja.cpp b/backend/ninja/Ninja.cpp index 044fb64..fb081de 100644 --- a/backend/ninja/Ninja.cpp +++ b/backend/ninja/Ninja.cpp @@ -411,23 +411,25 @@ namespace backend allLinkerFlags += " "; allLinkerFlags += binaryDependency; } - + + string staticLinkerFlags; if (!staticLinkerFlagCallbackFunc || libraryType == LibraryType::DYNAMIC) { - staticLinkerFlagCallbackFunc = [&allLinkerFlags](const string &linkerFlag) + staticLinkerFlagCallbackFunc = [&staticLinkerFlags](const string &linkerFlag) { - allLinkerFlags += " "; - allLinkerFlags += linkerFlag; + staticLinkerFlags += " "; + staticLinkerFlags += linkerFlag; }; } + string dynamicLinkerFlags; // TODO: Do same for cmake if (!sourceFiles.empty()) { - dynamicLinkerFlagCallback = [&allLinkerFlags](const string &linkerFlag) + dynamicLinkerFlagCallback = [&dynamicLinkerFlags](const string &linkerFlag) { - allLinkerFlags += " "; - allLinkerFlags += linkerFlag; + dynamicLinkerFlags += " "; + dynamicLinkerFlags += linkerFlag; }; } @@ -441,6 +443,8 @@ namespace backend Result linkerFlags = getLinkerFlags(config, staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallback, globalIncludeDirCallback, cflagsCallbackFunc); if (linkerFlags.isErr()) return Result::Err(linkerFlags.getErrMsg()); + + allLinkerFlags += staticLinkerFlags + dynamicLinkerFlags; result += dependencyExportIncludeDirs; result += "\n\n"; -- cgit v1.2.3