[cmake-developers] setting LINKER_LANGUAGE still adds -lstdc++

Eric Noulard eric.noulard at gmail.com
Tue Oct 9 02:20:25 EDT 2012


2012/10/9 James Bigler <jamesbigler at gmail.com>:
>
> I spent some time in the debugger to try and understand why CMake is making
> the decisions it is.  It comes down to this function which loops over all
> the LinkClosures and calls AddImplicitLinkInfo for all languages that
> *don't* match the language of the target.
>
> //----------------------------------------------------------------------------
> void cmComputeLinkInformation::AddImplicitLinkInfo()
> {
>   // The link closure lists all languages whose implicit info is needed.
>   cmTarget::LinkClosure const*
> lc=this->Target->GetLinkClosure(this->Config);
>   for(std::vector<std::string>::const_iterator li = lc->Languages.begin();
>       li != lc->Languages.end(); ++li)
>     {
>     // Skip those of the linker language.  They are implicit.
>     if(*li != this->LinkLanguage)
>       {
>       this->AddImplicitLinkInfo(*li);
>       }
>     }
> }
>
>
> The LinkClosure is computed and the only language in it is CXX due to the
> CXX-ness of the input sources.  I'm not sure what to think about this.  I
> told CMake to link the target as if it were a C target, then it decides that
> it needs CXX libraries because it found CXX sources in my library.
>
> If I go through the trouble of specifying that I want to link the library as
> if it were C, why do the source files get to override my property?
>
> It also seems to me that the source file language should only guide the link
> language when the user didn't specify it explicitly.

I agree with you even if it looks like a feature side-effect.

It looks like if you need to
set(CMAKE_CXX_LINKER_PREFERENCE_PROPAGATES 0)

in order to make your current problem disappear (at least on Linux)

I would bet that this "feature" did not include a test with a "single
source" file.
I would also bet that Brad should answer to this:

commit fcab87c9f802965318bee033c2fa3ff27cfbfec7
Author: Brad King <brad.king at kitware.com>
Date:   Thu Jul 30 10:59:37 2009 -0400

    Do not always propagate linker language preference

    The commit "Consider link dependencies for link language" taught CMake
    to propagate linker language preference from languages compiled into
    libraries linked by a target.  It turns out this should only be done for
    some languages, such as C++, because normally the language of the
    program entry point (main) should be used.

    We introduce variable CMAKE_<LANG>_LINKER_PREFERENCE_PROPAGATES to tell
    CMake whether a language should propagate its linker preference across
    targets.  Currently it is true only for C++.

commit fd633b33cff397b110cc69f82fd522cdf905952a
Author: Brad King <brad.king at kitware.com>
Date:   Thu Jul 30 10:59:25 2009 -0400

    Refactor target linker language selection

    This factors the decision logic out of cmTarget::ComputeLinkClosure into
    dedicated class cmTargetSelectLinker.  We replace several local
    variables with a single object instance, and organize code into methods.


-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org



More information about the cmake-developers mailing list