locked
[UWP]winrt component static library linking RRS feed

  • Question

  • Hello everyone! 

    I am developing a wrapper for some static c++ lib (that includes some 3d party) on UWP.

    I got a success on the desktop side, but I cannot deploy linked static lib on device.

    I've read ton of articles about this issue but I still don't get how to fix it.

    The most common solution is to deploy library as an app content.

    I already tried to do so, but I got confused how to locate the content lib in the wrapper linker. (I still have an error "the specified module could not be found" even if I see the target lib on the device)

    If somebody have an experience in this process please share it with me. I got stuck for so long with this issue.



    • Edited by Barry Wang Tuesday, September 27, 2016 9:13 AM title tag
    Monday, September 26, 2016 2:45 PM

Answers

  • Hi Alex,

    As far as I know, the WinRT Component in UWP which you use to wrap the third party lib needs to be set to dynamically-linked library (/MD or /MDd). If set to statically-linked library (/MT or /MTd) , error will occur as below:
    “Using static version of the C++ runtime library is not supported.”

    If you have set the component to /MD, but link a /MT lib to it, error will occur as below:
    “mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in pch.obj”
    It means that you are linking with different versions of the CRT. To correct this error, you need to use a /MD lib.

    For the architecture issue, you should use x86 for emulator and ARM for real device.

    Best Regards,
    David


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    • Proposed as answer by David_FF Friday, October 7, 2016 6:57 AM
    • Marked as answer by Barry Wang Monday, October 10, 2016 12:16 AM
    Thursday, September 29, 2016 10:07 AM

All replies

  • Hi Alex,

    As the MSDN library described, you could refer to the following steps to use a native C++ static library in a UWP project.

    1. In the project properties for the UWP project, in the Linker section, add the path to the library in the Input property. For example, for a library in the project that places its output in SolutionFolder\Debug\MyNativeLibrary\MyNativeLibrary.lib, add the relative path Debug\MyNativeLibrary\MyNativeLibrary.lib.
    2. Add an include statement to reference the header file to your pch.h in the UWP project and start add the code that uses the library.
          
      #include "..\MyNativeLibrary\giraffe.h"
           Do not add a reference in the References node in Solution Explorer. That mechanism only works for Windows Runtime Components.

    >> I got a success on the desktop side, but I cannot deploy linked static lib on device.

    Please make sure you have targeted the Platform to “All Platforms” in the Input property, so that it will work on both desktop and device.

    Best Regards,

    David


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.


    • Edited by David_FF Tuesday, September 27, 2016 9:44 AM
    Tuesday, September 27, 2016 9:43 AM
  • Thank you for your reply David

    This solution only works in case of /md static library 

    with the /mt param (which I need) I got an error that module could not be found

    >> Please make sure you have targeted the Platform to “All Platforms” in the Input property, so that it will work on both desktop and device.

    I have left only Release|Win32 arhitecture in my vcxproj wrapper file manually just to clean it and see all of the dependencies there. I am using x86 emulator and run only against x86 on the local machine. Could it be a problem there? Which architecture should I add then?

    Tuesday, September 27, 2016 10:11 AM
  • Hi Alex,

    As far as I know, the WinRT Component in UWP which you use to wrap the third party lib needs to be set to dynamically-linked library (/MD or /MDd). If set to statically-linked library (/MT or /MTd) , error will occur as below:
    “Using static version of the C++ runtime library is not supported.”

    If you have set the component to /MD, but link a /MT lib to it, error will occur as below:
    “mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in pch.obj”
    It means that you are linking with different versions of the CRT. To correct this error, you need to use a /MD lib.

    For the architecture issue, you should use x86 for emulator and ARM for real device.

    Best Regards,
    David


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    • Proposed as answer by David_FF Friday, October 7, 2016 6:57 AM
    • Marked as answer by Barry Wang Monday, October 10, 2016 12:16 AM
    Thursday, September 29, 2016 10:07 AM