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


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:

    public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
        if (target != BuildTarget.iOS)

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


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 {

	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);

			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


			"-lavcodec -lavformat -lavutil -lswresample");

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

Enjoy !