This sample demonstrates using the Sentry SDK from Objective-C++ when -fmodules and -fcxx-modules are not supported.
Originally documented the issue in getsentry/sentry-cocoa#4543. Now demonstrates the solution via SentryObjC.
Many projects cannot enable Clang modules:
- React Native (≤0.76): AppDelegate is
.mm(Objective-C++), modules disabled by default - Haxe: Build toolchain conflicts with
-fmodules/-fcxx-modules - Custom build systems: May not support module imports
With modules disabled:
@import Sentrydoes not work (requires modules)#import <Sentry/Sentry.h>exposes only the ObjC headers, not Swift APIs#import <Sentry/Sentry-Swift.h>fails with forward declaration errors (e.g.UIView,UIWindowLevel) when included from.mmfiles
Result: SentrySDK, SentryOptions, options.sessionReplay and other Swift-bridged APIs are unavailable. The SDK is effectively unusable from ObjC++ without modules.
The SentryObjC product (introduced in #6342) provides a pure Objective-C wrapper around the main SDK:
#import <SentryObjC.h> // Pure ObjC - no Swift modules required
[SentryObjCSDK startWithConfigureOptions:^(SentryOptions *options) {
options.dsn = @"...";
options.tracesSampleRate = @1.0;
options.sessionReplay.sessionSampleRate = 0; // All Swift APIs now available!
}];Key differences from the main Sentry framework:
- ✅ Pure Objective-C public interface
- ✅ No Swift modules or
Sentry-Swift.hrequired - ✅ Works in Objective-C++ (
.mmfiles) without modules - ✅ Full access to all SDK features (SentrySDK, SentryOptions, sessionReplay, etc.)
- Uses Objective-C++ (
.mmfiles) for AppDelegate and ViewController - Sets
CLANG_ENABLE_MODULES = NOin the build configuration - Depends on SentryObjC (SPM product) and imports
#import <SentryObjC.h> - Builds successfully with full access to SentrySDK, SentryOptions, sessionReplay, etc.
cd Samples/iOS-ObjectiveCpp-NoModules
xcodegen generateOr from the repo root:
make build-sample-iOS-ObjectiveCpp-NoModules