I recently upgraded my project from 5.3.5f1 to 5.4.0f3 and am now getting compiler errors in Xcode when I export my Unity project to an iOS project. The errors show in the file iPhone_Sensors.h, giving the following message: “Unknown type name “class” did you mean “Class”?” Which makes it seem like there is a syntax error in that file, OR that the header is being included by a file that it shouldn’t be. Well, I ALSO exported an iOS project from an empty Unity project, just to see what happened, and that same exact header file was created, and it was being included by the same exact other files (iPhone_Sensors.mm, UnityAppController.mm, and UnityView.h), and this time there were no errors at all.
I’ve attached an image of what I’m seeing. I really think the errors are red herrings, and the actual issue is something deeper… but I’m just not sure what to try next. Any insight or help would be greatly appreciated!
From within the Xcode project, open Classes/UI/UnityView.h and delete the following import statement line:
#include iPhone_Sensors.h
Explanation
(Disclaimer: I am not an expert on the subject)
This bug started happening for me when I upgraded to Unity 5.4. I happened to have an old version of the Xcode project for the game lying around (exported using Unity 5.3) so I decided to do a manual diff.
Opening both projects, and doing a mass-find-in-entire-project for iPhone_Sensors.hreveals that the header is included in two places in 5.3 but three places in 5.4, and the new file to have it is, you guessed, it, UnityView.h
To my understanding, the compiler error above means “Hey, I expected this code to be Objective-C++ but it’s actually plain C++, what gives?” Well, the reason it’s happening is because somewhere in our project there’s a file that depends on UnityView.h which in turn depends on iPhone_Sensors.h and expects the entire stack from top to bottom to be the same language, but it’s not. Removing the line fixes the issue by simply cutting out the chunk of code that is in the incorrect language.
Now, some questions still remain:
(1) Why did Unity add this import line? I have no idea, but removing it causes no issues, the game compiles and plays fine.
(2) Why doesn’t this happen in a vanilla project? Most likely because the dependency comes from a plugin, or some custom code we wrote unwittingly. Very common in large projects.
I ended up getting to a solution with the help of a friend. I don’t know what side effects this might have or if it would be recommended by Unity, but it got me past the issue and my XCode project was able to compile.
In XCode, go to Build Settings and view by Levels. Then in the search bar type “compile souce” and it should leave you with only a couple sections. In “Apple LLVM 7.1 - Language”, change the “Resolved” and “Unity-iPhone” columns to “Objective-C++”. I’ve attached a screen grab to help show this.
That worked for me! Hopefully it works for anyone else encountering this obscure problem.
Thanks for posting your solution. I have the same issue but unfortunately I need to go deeper down this rabbit hole since the change to Compile Sources As (from ‘According to File Type’ to Objective C++) created more errors. I have a C# script in Unity that imports a bunch dlls so that I can call into Objective-C from Unity - defined in my MonoBehaviour like this:
public class FullscreenWebView : MonoBehaviour {
[DllImport ("__Internal")]
private static extern void LoadWebViewNative(string url);
[DllImport ("__Internal")]
private static extern void LoadPermissions(bool allowClick);
//there are 12 of these in total
//followed by the corresponding public methods...
public static void OpenURL (string url) {
Debug.Log("Opening url: " + url);
if (Application.platform == RuntimePlatform.IPhonePlayer) {
LoadWebViewNative(url);
} else {
Debug.LogError("this platform not supported yet");
}
}
//etc....there are 12 of these in the script
After changing the Source Compiler to Objective C++ I now get the following compile error:
"__LoadWebViewNative", referenced from:
_FullscreenWebView_OpenURL_m1977336870 in Bulk_Assembly-CSharp-firstpass_0.o
_FullscreenWebView__LoadWebViewNative_m1106552972 in Bulk_Assembly-CSharp-firstpass_0.o
(maybe you meant: _FullscreenWebView__LoadWebViewNative_m1106552972)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
(same error repeated for each imported call from Unity.)
I have been scouring the forums and have discovered lots of others with similar issues and it seems to be something to do with Objective-c and c++ and c# not getting along…problem is I can’t seem to resolve it. It seems that by changing the source compiler to Objective-C++ xCode doesn’t know how to interpret the c# script which leads me to believe that the c# script is formatted incorrectly.
Also, why did the ‘Compile Source As’ setting need to be changed in the first place?
Also, I have 3 plugin files in the project which relate to the c# file in question:
In my case, the file that was failing compilation was a ‘.m’ file that imported UnityView.h. I changed the extension of this file to ‘.mm’. This forced the compiler to treat the file as Objective-C++ code (since UnityView.h appears to be Objective-C and iPhone_Sensors.h appears to be C++). Note that ‘Compile Sources As’ must be set to ‘According to File Type’ for this to work.