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 --- src/CmakeModule.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/CmakeModule.cpp b/src/CmakeModule.cpp index 35e4884..990bf36 100644 --- a/src/CmakeModule.cpp +++ b/src/CmakeModule.cpp @@ -41,20 +41,23 @@ namespace sibs allLinkerFlags += binaryDependency; } #endif + + string staticLinkerFlags; if (!staticLinkerFlagCallbackFunc || (config.getPackageType() == PackageType::DYNAMIC || config.getPackageType() == PackageType::LIBRARY)) { - staticLinkerFlagCallbackFunc = [&allLinkerFlags](const string &linkerFlag) + staticLinkerFlagCallbackFunc = [&staticLinkerFlags](const string &linkerFlag) { - allLinkerFlags += " "; - allLinkerFlags += linkerFlag; + staticLinkerFlags += " "; + staticLinkerFlags += linkerFlag; }; } + string dynamicLinkerFlags; // TODO: If project contains no source files, then we shouldn't override this function - dynamicLinkerFlagCallbackFunc = [&allLinkerFlags](const string &linkerFlag) + dynamicLinkerFlagCallbackFunc = [&dynamicLinkerFlags](const string &linkerFlag) { - allLinkerFlags += " "; - allLinkerFlags += linkerFlag; + dynamicLinkerFlags += " "; + dynamicLinkerFlags += linkerFlag; }; // TODO: Create a cmake module that contains library/include path for the dependencies (https://cmake.org/Wiki/CMake:How_To_Find_Libraries). @@ -105,6 +108,8 @@ namespace sibs Result globalLibResult = GlobalLib::getLibs(globalLibDependencies, config, globalLibDir, staticLinkerFlagCallbackFunc, dynamicLinkerFlagCallbackFunc, globalIncludeDirCallback); if(!globalLibResult) return globalLibResult; + + allLinkerFlags += staticLinkerFlags + dynamicLinkerFlags; Result createBuildDirResult = createDirectoryRecursive(buildPath.c_str()); if (createBuildDirResult.isErr()) -- cgit v1.2.3