Skip to content

[Bug] Fix: iOS build fails on React Native 0.81+ due to C++ standard mismatch #2

@Mr-KID-github

Description

@Mr-KID-github

Hello cactus-react-native maintainers,

First off, thank you for your work on this great project!

The Problem

After upgrading my React Native project to a recent version (e.g., 0.81.x or higher), I encountered an iOS build failure.

The key error message occurs when compiling Cactus.mm, which includes headers from React Native's core:

.../ios/Pods/Headers/Public/ReactCommon/react/bridging/Base.h:65:3: error: unknown type name 'requires'

Root Cause

After investigating, the root cause is that recent versions of React Native's core headers (specifically react/bridging/Base.h) now use C++20 language features, such as therequires keyword.

However, the cactus-react-native.podspec file explicitly forces the C++ standard to c++17, which causes the compiler to fail when it encounters the new syntax.

The problematic line is in cactus-react-native.podspec:

s.pod_target_xcconfig = {
  ...
  "OTHER_CPLUSPLUSFLAGS" => base_optimizer_flags + " -std=c++17"
}

The Solution

The solution is to update the C++ standard in the .podspec file from c++17 to c++20. This small change makes the library compatible with the latest versions of React Native.

The specific change is as follows:

- "OTHER_CPLUSPLUSFLAGS" => base_optimizer_flags + " -std=c++17"
+ "OTHER_CPLUSPLUSFLAGS" => base_optimizer_flags + " -std=c++20"

Environment

  • React Native Version: 0.81.1 (and higher)
  • cactus-react-native Version: 0.2.10
  • Platform: iOS
  • Xcode Version: 15.x

Hope this feedback helps improve the project.

Thanks again for all your hard work!

Here is the diff that solved my problem:

diff --git a/node_modules/cactus-react-native/android/.project b/node_modules/cactus-react-native/android/.project
new file mode 100644
index 0000000..2c34a94
--- /dev/null
+++ b/node_modules/cactus-react-native/android/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>cactus-react-native</name>
+	<comment>Project cactus-react-native created by Buildship.</comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
+	</natures>
+	<filteredResources>
+		<filter>
+			<id>1757258733415</id>
+			<name></name>
+			<type>30</type>
+			<matcher>
+				<id>org.eclipse.core.resources.regexFilterMatcher</id>
+				<arguments>node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments>
+			</matcher>
+		</filter>
+	</filteredResources>
+</projectDescription>
diff --git a/node_modules/cactus-react-native/cactus-react-native.podspec b/node_modules/cactus-react-native/cactus-react-native.podspec
index 5225f9d..4cceae4 100644
--- a/node_modules/cactus-react-native/cactus-react-native.podspec
+++ b/node_modules/cactus-react-native/cactus-react-native.podspec
@@ -32,7 +32,7 @@ Pod::Spec.new do |s|
   s.pod_target_xcconfig = {
     "OTHER_LDFLAGS" => base_ld_flags,
     "OTHER_CFLAGS" => base_optimizer_flags,
-    "OTHER_CPLUSPLUSFLAGS" => base_optimizer_flags + " -std=c++17"
+    "OTHER_CPLUSPLUSFLAGS" => base_optimizer_flags + " -std=c++20"
   }
 
   # Don't install the dependencies when we run `pod install` in the old architecture.

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions