Home > OS >  Use existing Static library in C WinRT UWP app
Use existing Static library in C WinRT UWP app

Time:02-06

I have existing third party static library that I want to use in my project C WinRT UWP app. Can I do that? I have read documentation at https://docs.microsoft.com/en-us/cpp/porting/how-to-use-existing-cpp-code-in-a-universal-windows-platform-app?view=msvc-170 But it has me confused. Doc talk about "Using a native C static library in a UWP App" what is native c library?. Also I do not have source code for this library.

CodePudding user response:

I have an existing third-party static library that I want to use in my project C WinRT UWP app. Can I do that? Also, I do not have the source code for this library.

Yes. You don't need the source code to use a library.

You can just use the binary library ( the final output from the source ) that is provided. It can be included as either a static or dynamic library in your final output binary.

How to include that?

Referring to some portion from the doc for your third party static library that may help.

To use a native C   static library in a UWP project
In the project properties for the UWP project, 

choose Configuration Properties > Linker > Input in the left pane. 

In the right pane, add the path to the library in the Additional Dependencies 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.

Add a include statement to reference the header file to your pch.h file (if present), 
or in any .cpp file as needed, and start adding code that uses the library.

C  

Copy
#include "..\MyNativeLibrary\MyNativeLibrary.h"

CodePudding user response:

The primary limitation for UWP is that the library:

(a) Must use the subset of Win32 imports that are supported for use in WINAPI_PARTITION_APP

(b) It needs to have been built with VS 2015 Update 3 or later in order to be 'binary compatible' with modern Visual C tooling used for UWP.

(c) Some APIs that are used by the static library may not be supported in the "AppContainer" security context (i.e. they may fail in ways the code doesn't handle gracefully).

You should also use /NODEFAULTLIB:kernel32.lib to avoid having your static library force the import of non-supported APIs. The "WindowsApp.lib" umbrella library provides everything that's supported.

More than likely, you'll need the static library built with some modification to actually link successfully and eventually pass WACK.

  •  Tags:  
  • Related