Realm-cocoa: Expected Identifier in RLMCollection.h

Created on 13 Nov 2017  ·  14Comments  ·  Source: realm/realm-cocoa

Goals

I'm refactoring an Objective-C project so that it compiles on Xcode 9.1

Expected Results

The project should build successfully

Actual Results

The compiler errors out citing RLMCollection.h

Tooling

Realm framework version: Realm Cocoa 3.0.2 via Cocoapods

  pod 'Realm',      :git => "https://github.com/realm/realm-cocoa.git", 
                    :branch => "master", 
                    :submodules => true

Xcode version: 9.1

iOS/OSX version: 11.1/10.13

Issue

When I build this project, I get this error:

screenshot 2017-11-13 11 48 27

RLMCollection.h:26
[Error] Expected Identifier or '{'
[Warn] Declaration does not declare anything

I've tried a few versions of Realm (including 3.0.2), and my last attempt was with master, as shown in my Podfile excerpt.

I tried setting up a blank Obj-C project in Xcode 9 with the same Podfile setup. However, that project builds. I'm at a loss as to what could be affecting the compiler here.

Any suggestions would go a long way. Thank you!

T-Help

Most helpful comment

That's a lot less revealing than I'd hoped ☹️

The only thing at all odd that I see is that the file has a .m extension but is being compiled as Objective-C++…

Yup, that's it. When compiling as C++98, typedef NS_ENUM(int, FooBarBaz); isn't valid for whatever reason. I'd suggest either:

  1. Changing the file to build as Objective-C, if there's no good reason for it to be building as Objective-C++.
  2. Changing the C++ language version used to C++11 or newer (via the CLANG_CXX_LANGUAGE_STANDARD build setting). There's no good reason to be using C++98 at this point in time.

All 14 comments

Can you please do the following:

  1. Open your workspace that includes the Realm pod.
  2. Open RLMCollection.mm.
  3. Product -> Perform Action -> Preprocess
  4. Copy-paste the resulting output into a new file.
  5. Share it here (probably via a Gist, since it'll be huge).

That'll show us the code after the preprocessor has been run, which will give us a better idea as to why the compiler is having trouble with that code.

@thatjuan, the output you shared appears to be truncated. It includes only ~18,000 lines and finishes in the middle of Foundation's class declaration for NSDateComponents. I'd expect your output to be at least 150,000 lines, and it should end with RLMCollection.mm's declarations of RLMAddNotificationBlock.

Oh, actually, GitHub is just being misleading… If I look at the raw version of the file, I see all of the lines I expect to see.

It looks like this is the bit that's failing?

@class RLMRealm, RLMResults, RLMSortDescriptor, RLMNotificationToken, RLMCollectionChange;
typedef enum __attribute__((enum_extensibility(open))) RLMPropertyType : int32_t RLMPropertyType; enum RLMPropertyType : int32_t;

Circa line 60710

Yes, and your preprocessed version of it looks identical to what I see locally.

Can you please double-check which file Xcode is failing to build when you're seeing the "Expected Identifier or '{'" error message? If it's something other than RLMCollection.mm, which I suspect it must be, can you repeat the steps I listed above for that file instead?

screenshot 2017-11-13 13 19 45

I believe that's the one. It's in RLMCollection.h.

That shows the header that the error was encountered in. What we need to know is which file was being compiled that then included the header. You can look at the full build log in Xcode's Report Navigator (View -> Navigators -> Show Report Navigator, then finding the most recent failing build) to see which file was being compiled when the error was encountered.

Ah, gotcha.. Yes, the file being compiled is the class that uses Realm. When I go to pre-process that file, xcode says "Unable to Generate Content".

That file defines a class that uses Realm in it, and it includes Realm via

#import <Realm/Realm.h>

Very strange that Xcode cannot preprocess it…

Can you copy-paste the relevant "Compile Foo.m" line from the build log here (click on the failing line, Edit -> Copy)? Copy-pasting will include the command-line showing how the compiler was invoked and the entirety of the error output, which will likely include details that Xcode doesn't show in its sidebar or inline error UI. That may reveal what's going on.

That's a lot less revealing than I'd hoped ☹️

The only thing at all odd that I see is that the file has a .m extension but is being compiled as Objective-C++…

Yup, that's it. When compiling as C++98, typedef NS_ENUM(int, FooBarBaz); isn't valid for whatever reason. I'd suggest either:

  1. Changing the file to build as Objective-C, if there's no good reason for it to be building as Objective-C++.
  2. Changing the C++ language version used to C++11 or newer (via the CLANG_CXX_LANGUAGE_STANDARD build setting). There's no good reason to be using C++98 at this point in time.

@bdash you're the man! This project has been around since Xcode 3 and it's got a fair amount of baggage. Changing the C++ version to 11 got me past that error and on to a few that appear more palatable.

Thank you for taking the time to help me out :D

I have encountered the same problem.

But I commented out this line of code:
typedef NS_ENUM(int32_t, RLMPropertyType);

Then added a new line of code:
#import <Realm/RLMConstants.h>

it work

Was this page helpful?
0 / 5 - 0 ratings