Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Creating and Linking Against C Static Libraries

Antoine Haas edited this page Aug 23, 2016 · 5 revisions

#Creating and Linking Against C++ Static Libraries

Follow the instructions below to have your Objective-C application project link against a C++ static library.

Creating C++ Static Libraries

  1. In Visual Studio, right-click (1) on your solution and select Add (2) -> New Project... (3).

![](https://github.com/Microsoft/WinObjC/wiki/images/Creating and Linking Against C++ Static Libraries/new_project.png)

  1. Under Installed (1) -> Visual C++ (2) -> Windows (3) -> Universal (4), select Static Library (Universal Windows) (5).

![](https://github.com/Microsoft/WinObjC/wiki/images/Creating and Linking Against C++ Static Libraries/new_static_lib.png)

  1. Name (1) your library project and click OK (2).

![](https://github.com/Microsoft/WinObjC/wiki/images/Creating and Linking Against C++ Static Libraries/my_lib.png)

  1. When you're prompted to choose the platform version of your app, choose Windows 10 Anniversary Edition (10.0, Build 14393) (2) as the target version and Windows 10 (10.0, Build 10586) (1) as the minimum version.

![](https://github.com/Microsoft/WinObjC/wiki/images/Creating and Linking Against C++ Static Libraries/platform_version.png)

Now that the library project has been added to your solution, you can edit it to add the functionality you need for your application. Once you're done, follow the steps below to link your Objective-C project against it.

Linking Objective-C projects to C++ Static Libraries

  1. In Visual Studio, under your Objective-C project node that will be using the library, right-click on References (1) and select Add Reference... (2).

![](https://github.com/Microsoft/WinObjC/wiki/images/Creating and Linking Against C++ Static Libraries/references.png)

  1. Under Projects (1) -> Solution (2), check your library (3) and click OK (4).

![](https://github.com/Microsoft/WinObjC/wiki/images/Creating and Linking Against C++ Static Libraries/my_lib_reference.png)

  1. Right-click (1) on your Objective-C project and select Properties (2).

![](https://github.com/Microsoft/WinObjC/wiki/images/Creating and Linking Against C++ Static Libraries/properties.png)

  1. Select Paths (3) under Configuration Properties (1) -> Clang (2).

![](https://github.com/Microsoft/WinObjC/wiki/images/Creating and Linking Against C++ Static Libraries/paths.png)

  1. Add $(SolutionDir)\MyLib (1) to User Include Paths, where MyLib is the name of your library project. Add this path to all configurations of your project, by selecting each Configuration (2) and re-adding the same path. When you're done, click OK (3).

![](https://github.com/Microsoft/WinObjC/wiki/images/Creating and Linking Against C++ Static Libraries/user_include_paths.png)

  1. For each source file that will use the library, right-click (1) on it, select Rename and change the file extension to .mm so that it is compiled as Objective-C++.

![](https://github.com/Microsoft/WinObjC/wiki/images/Creating and Linking Against C++ Static Libraries/rename.png)

That's it! You should now be able to include your C++ library in your .mm files using the include directive with double quotes (1) and call its C++ functions (2).

![](https://github.com/Microsoft/WinObjC/wiki/images/Creating and Linking Against C++ Static Libraries/my_lib_include.png)

Clone this wiki locally