How to specify -ObjC in Other Linker Flag in Xcode with Unity 5

Hello,

When I try to build my Unity project to Xcode project the -ObjC in Other Linker Flag is missing but I have to add this flag.

Is it possible to add automatically this flag with Unity?

Hi. You can use third party XUPorter: GitHub - onevcat/XUPorter: Add files and frameworks to your Xcode project after it is generated by Unity 3D.

But, if you are using Unity5 it’s better to use UnityEditor.iOS.Xcode.PBXProject.

Here is a documentation: Unity - Scripting API: PBXProject

Here is an example: 1

This is short example:

    [PostProcessBuild(700)]
    public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
    {
        if (target != BuildTarget.iOS)
        {
            return;
        }

        string projPath = pathToBuiltProject + "/Unity-iPhone.xcodeproj/project.pbxproj";
        PBXProject proj = new PBXProject();
        proj.ReadFromString(File.ReadAllText(projPath));
        string targetGUID = proj.TargetGuidByName("Unity-iPhone");
        proj.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-ObjC"); 
        File.WriteAllText(projPath, proj.WriteToString());
    }

2019…

Here’s exactly how you do it with modern syntax - enjoy!

using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;


public class BuildPostProcessor {

	[PostProcessBuildAttribute(1)]
	public static void OnPostProcessBuild(BuildTarget target, string path) {

		Debug.Log(">> Automation by Fattie .2019 <<");

		if (target == BuildTarget.iOS) {

			PBXProject project = new PBXProject();
			string sPath = PBXProject.GetPBXProjectPath(path);
			project.ReadFromFile(sPath);

			string tn = PBXProject.GetUnityTargetName();
			string g = project.TargetGuidByName(tn);

			ModifyAsDesired(project, g);

			File.WriteAllText(sPath, project.WriteToString());
		}
	}

	static void ModifyAsDesired(PBXProject project, string g) {

		// add hella frameworks

		project.AddFrameworkToProject(g, "VideoToolbox.framework", false);
		project.AddFrameworkToProject(g, "libz.tbd", false);
		project.AddFrameworkToProject(g, "libbz2.tbd", false);

		// go insane with build settings

		project.AddBuildProperty(g,
			"LIBRARY_SEARCH_PATHS",
			"../FFmpeg-iOS/lib");

		project.AddBuildProperty(g,
			"OTHER_LDFLAGS",
			"-lavcodec -lavformat -lavutil -lswresample");
	}
}

Call it BuildPostProcessor.csd and put it in /Assets/Editor.

Enjoy !