none
Metro Style App Exe + Metroy Style Static Library linking

    Question

  • I have a WinRT application project (.exe) that contains WinRT native static C++ library (.lib). Itention of that static library is to handle all platform (winRT) specific features like creating window and activity lifecycle ( including main() function ).

    It's not linking because it's complaining of multiply defined symbols related to the threading model libraries:

    vccorlibd.lib(tmmta.obj) : error LNK2005: "int __abi___threading_model" (?__abi___threading_model@@3HA) already defined in vccorlibd.lib(tmdefault.obj)
    
    fatal error LNK1169: one or more multiply defined symbols found
    

    Is that good to generate Metroy Style App exe (Windows Store App Support) witch include Static Library (Windows Store App Support) or do I have to create Windows Runtime Component / DLL Windows Store App ?

    If that what I am doing is wrong, how can I create base WinRT library that will be linked to any other Metro Style App project ?

    Thanks

     

     

     

     

     

     

     

     


    • Edited by Angin3 Wednesday, August 29, 2012 3:18 PM Code block formating
    Wednesday, August 29, 2012 3:17 PM

Answers

  • Hello Angin3,

    I have few extra questions:

      • Does this issue happen only for debug build?
      • From your looks that the main function is in the static library what is reasoning for that?

    I suspect that because that you have main function in the static library this particular symbol is linked with your library and with the executable. The particular symbol is pulled by linker when you define [MTAThreadAttiribute] in your code. From the design point of view the executable has knowledge how WinRt should be initialized and this attribute should be used there.

    From the information that you provided the best fix is to move main(::Platform::Array<::Platform::String^>^) function to your executable.

    The mentioned by Jesse solution with /FORCE switch is not recommended because it’s possible that you will specify different threading models in static library and executable that may lead to further issues letter. Besides this is very fragile since the linker can take any symbol that will find first.

    Please let me know if this fixed your problem.

    Thanks!

    Lukasz

    Thursday, August 30, 2012 6:43 PM

All replies

  • Hi,

    I think both your exe and static library link the CRT, so that the error throw
    "fatal error LNK1169: one or more multiply defined symbols found"

    You can set (/FORCE:MULTIPLE) in your exe
    http://msdn.microsoft.com/en-us/library/70abkas3(v=vs.110).aspx

    Right Click your project->Properties->Configuration properties->Linker->General->Force File Output select
    Multiply Defined Symbol Only (/FORCE:MULTIPLE)

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, August 30, 2012 8:27 AM
    Moderator
  • Hello Angin3,

    I have few extra questions:

      • Does this issue happen only for debug build?
      • From your looks that the main function is in the static library what is reasoning for that?

    I suspect that because that you have main function in the static library this particular symbol is linked with your library and with the executable. The particular symbol is pulled by linker when you define [MTAThreadAttiribute] in your code. From the design point of view the executable has knowledge how WinRt should be initialized and this attribute should be used there.

    From the information that you provided the best fix is to move main(::Platform::Array<::Platform::String^>^) function to your executable.

    The mentioned by Jesse solution with /FORCE switch is not recommended because it’s possible that you will specify different threading models in static library and executable that may lead to further issues letter. Besides this is very fragile since the linker can take any symbol that will find first.

    Please let me know if this fixed your problem.

    Thanks!

    Lukasz

    Thursday, August 30, 2012 6:43 PM
  • You are correct. As you mentioned before Jesse solution can be a gambling ( but it works ).

    About your question - static library in that case is abstraction layer library where I have all of my platform specific code ( including main() function ). This is very useful to link with other projects/tests/examples. I don't have to create everywhere main() function. I have extern function placed in main witch have to be defined by executable project to create Application class.

    I figure out that my solution is to #include header with object where i define my main(), then executable code can link properly.

    Thanks!

    Angin3

    Ps. Pozdrawiam :)


    • Edited by Angin3 Friday, August 31, 2012 8:40 AM
    Friday, August 31, 2012 7:35 AM
  • Hi,

    I am having exactly the same problem, it's so good not to be alone! :-)

    Angin3, I am not sure I understand what you mean by "#include header with object where i define my main()" could you please give some more details? I'm so close now!

    Thanks!

    Tuesday, September 25, 2012 4:47 PM
  • bump! :)
    Wednesday, October 03, 2012 11:21 AM