Skip to content

Commit 6a6276b

Browse files
YUNQIUGUOrachguo
authored and
Prathik Rao
committed
[js/rn] Fix extensions header include issue (#15800)
### Description <!-- Describe your changes. --> Identified the cause for a `redefinition compilation error` happened in a react native expo app with ort-extensions enabled when running the ios side. Fix the include path now, so we can remove the temporary forward declaration in OnnxruntimeModule.mm file. ### Motivation and Context <!-- - Why is this change required? What problem does it solve? - If it fixes an open issue, please link to the issue here. --> Fix implementation detail. --------- Co-authored-by: rachguo <[email protected]>
1 parent 04321f7 commit 6a6276b

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

js/react_native/ios/OnnxruntimeModule.mm

+11-10
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66

77
#import <Foundation/Foundation.h>
88
#import <React/RCTLog.h>
9-
#import <onnxruntime/onnxruntime_cxx_api.h>
109

10+
// Note: Using below syntax for including ort c api and ort extensions headers to resolve a compiling error happened
11+
// in an expo react native ios app when ort extensions enabled (a redefinition error of multiple object types defined
12+
// within ORT C API header). It's an edge case that compiler allows both ort c api headers to be included when #include
13+
// syntax doesn't match. For the case when extensions not enabled, it still requires a onnxruntime prefix directory for
14+
// searching paths. Also in general, it's a convention to use #include for C/C++ headers rather then #import. See:
15+
// https://google.github.io/styleguide/objcguide.html#import-and-include
16+
// https://microsoft.github.io/objc-guide/Headers/ImportAndInclude.html
1117
#ifdef ORT_ENABLE_EXTENSIONS
12-
extern "C" {
13-
// Note: Declared in onnxruntime_extensions.h but forward declared here to resolve a build issue:
14-
// (A compilation error happened while building an expo react native ios app, onnxruntime_c_api.h header
15-
// included in the onnxruntime_extensions.h leads to a redefinition conflicts with multiple object defined in the ORT C
16-
// API.) So doing a forward declaration here instead of #include "onnxruntime_extensions.h" as a workaround for now
17-
// before we have a fix.
18-
// TODO: Investigate if we can include onnxruntime_extensions.h here
19-
OrtStatus *RegisterCustomOps(OrtSessionOptions *options, const OrtApiBase *api);
20-
} // Extern C
18+
#include "onnxruntime_cxx_api.h"
19+
#include "onnxruntime_extensions.h"
20+
#else
21+
#include "onnxruntime/onnxruntime_cxx_api.h"
2122
#endif
2223

2324
@implementation OnnxruntimeModule

js/react_native/ios/TensorHelper.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@
55
#define TensorHelper_h
66

77
#import <Foundation/Foundation.h>
8-
#import <onnxruntime/onnxruntime_cxx_api.h>
8+
9+
// Note: Using below syntax for including ort c api and ort extensions headers to resolve a compiling error happened
10+
// in an expo react native ios app (a redefinition error happened with multiple object types defined within
11+
// ORT C API header). It's an edge case that the compiler allows both ort c api headers to be included when #include
12+
// syntax doesn't match. For the case when extensions not enabled, it still requires a onnxruntime prefix directory for
13+
// searching paths. Also in general, it's a convention to use #include for C/C++ headers rather then #import. See:
14+
// https://google.github.io/styleguide/objcguide.html#import-and-include
15+
// https://microsoft.github.io/objc-guide/Headers/ImportAndInclude.html
16+
#ifdef ORT_ENABLE_EXTENSIONS
17+
#include "onnxruntime_cxx_api.h"
18+
#else
19+
#include "onnxruntime/onnxruntime_cxx_api.h"
20+
#endif
921

1022
@interface TensorHelper : NSObject
1123

0 commit comments

Comments
 (0)