You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/CppInteroperability/GettingStartedWithC++Interop.md
+11-10Lines changed: 11 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
# Getting started with C++ Interoperability
1
+
# Getting started with C++ Interoperability
2
2
3
3
This document is designed to get you started with bidirectional API-level interoperability between Swift and C++.
4
4
@@ -32,10 +32,10 @@ module Cxx {
32
32
- In your xcode project, follow the steps [Creating a Module to contain your C++ source code](#creating-a-module-to-contain-your-c-source-code) in your project directory
33
33
34
34
Add the C++ module to the include path and enable C++ interop:
35
-
- Navigate to your project directory
35
+
- Navigate to your project directory
36
36
- In `Project` navigate to `Build Settings` -> `Swift Compiler`
37
37
- Under `Custom Flags` -> `Other Swift Flags` add`-enable-experimental-cxx-interop`
38
-
- Under `Search Paths` -> `Import Paths` add your search path to the C++ module (i.e, `./ProjectName/Cxx`). Repeat this step in `Other Swift Flags`
38
+
- Under `Search Paths` -> `Import Paths` add your search path to the C++ module (i.e, `./ProjectName/Cxx`). Repeat this step in `Other Swift Flags`
39
39
40
40
```
41
41
//Add to Other Swift Flags and Import Paths respectively
@@ -64,18 +64,19 @@ struct ContentView: View {
64
64
#ifndef Cxx_hpp
65
65
#define Cxx_hpp
66
66
67
-
int cxxFunction(int n) {
68
-
return n;
69
-
}
67
+
int cxxFunction(int n);
68
+
70
69
#endif
71
70
```
72
71
73
72
```
74
73
//In Cxx.cpp
75
74
76
75
#include "Cxx.hpp"
77
-
int cxxFunction(int n);
78
76
77
+
int cxxFunction(int n) {
78
+
return n;
79
+
}
79
80
80
81
```
81
82
@@ -134,7 +135,7 @@ let package = Package(
134
135
import Cxx
135
136
136
137
public struct CxxInterop {
137
-
138
+
138
139
public func callCxxFunction(n: Int32) -> Int32 {
139
140
return cxxFunction(n: n)
140
141
}
@@ -152,7 +153,7 @@ After creating your project follow the steps [Creating a Module to contain your
152
153
- In`add_library` invoke `cxx-support` with the path to the C++ implementation file
153
154
- Add the `target_include_directories` with `cxx-support` and path to the C++ Module `${CMAKE_SOURCE_DIR}/Sources/Cxx`
154
155
- Add the `add_executable` to the specific files/directory you would like to generate source, with`SHELL:-enable-experimental-cxx-interop`.
155
-
- In the example below we will be following the file structure used in [Creating a Swift Package](#Creating-a-Swift-Package)
156
+
- In the example below we will be following the file structure used in [Creating a Swift Package](#Creating-a-Swift-Package)
156
157
157
158
```
158
159
//In CMakeLists.txt
@@ -199,7 +200,7 @@ CxxInterop.main()
199
200
200
201
- In your project's directory, run `cmake` to generate the systems build files
201
202
202
-
- To generate an Xcode project run `cmake -GXcode`
203
+
- To generate an Xcode project run `cmake -GXcode`
203
204
- To generate with Ninja run `cmake -GNinja`
204
205
205
206
- For more information on `cmake` see the 'GettingStarted' documentation: (https://github.com/apple/swift/blob/main/docs/HowToGuides/GettingStarted.md)
0 commit comments