So, in short, what I am trying to do is set some specific linker flags in Xcode for a project I’m working on. I’ve got my *.Build.cs set up to include my custom paths, headers and libraries, as well as required iOS Frameworks, but I can’t seem to find any examples or documentation for setting linker flags (“Other Linker Flags”, in Xcode build settings terminology.) As a for instance, I need to add the -ObjC linker flag for this project.
Is there any way to achieve this?
Thanks for your time!
Linker and compiler flags are set in the platform toolchain .cs files in UnrealBuildTool. If you want to modify them, you’d have to get UnrealBuildTool source from GitHub and compile it yourself. Should not be hard nor time consuming. If you need any help with that, let me know.
Not sure if you’re allowed to “bump”, but figured since I posted over the weekend I might just give this a quick boost. Really, any way to add a linker flag would be sufficient at this point, even if its not something that can be automated as part of the UE build process. In fact, I’d be satisfied if the answer is simply that this isn’t possible right now, though, I would like to vote that it be added if not.
Thanks for your response! I haven’t had a chance yet to look through the UBT source code, I actually missed it when I originally went to find it and thought it must be in a different repo. I’m assuming it can be built separately from the engine itself? If so, may ask a more specific question?
First, to better describe my situation: the intention is to provide a plugin of sorts, which depends on the flag I mentioned in my original post (as well as others). The hope being that other UE4 game developers can use this plugin within their games. The plugin itself communicates with many iOS *Kit frameworks and is itself written in Objective-C, so, at the source level, the plugin is actually a wrapper. My question (maybe more of an observance) is that providing a custom version of the UBT to enable the plugin to be used seems a little extreme? I guess at this point there would be no other alternative, is there any plan in the future to expose compile/link options at a higher level? Or would possibly such a modification be considered for a pull request, were it added?
Thanks again for your response!
Thanks for your quick responses. Yeah, I see how this is structured now, should be simple to build and test things out.
I think a general solution is the best way. Beyond needing more than just the -ObjC flag, its definitely not a flag you want to set unless you need it, since it will increase the size of app/executable.
Thanks very much for entertaining my questions. I have enough to continue my investigation now. Really enjoying UE4, by the way, just dauntingly impressive.
Missed that second comment. Its definitely required for the original 3rd party framework which the plugin is wrapping. The framework also utilizes ARC, so, -fobjc-arc flag is also required, for instance.
Yes, you can build UBT itself without rebuilding the full engine. There’s a UnrealBuildTool_Mono.csproj that you can build with Mono’s xbuild (Engine/Build/BatchFiles/Mac/Build.sh does that using Mono we bundle with the engine).
As for optional -ObjC (or any flags) support, we’ll figure something out. We definitely want to make it possible to create plugins distributed in binary form, so we will need some solution for this. I suppose that maybe we could enable -ObjC for all plugins by default, but a more general solution for custom compile and link flags is an interesting idea. I’ll discuss this with folks here.
Also, I don’t think people would need -ObjC to link to your plugin, that should help.
No problem, glad I could help. And I’m glad you’re enjoying working with the engine. If you need anything else, just let me know.
Ah, OK. Good to know. The more reason to add support for custom flags in Build.cs files. We’ll look into this.
One more thing. I’m not sure I understand why do you need -ObjC exactly… Could you explain, please? Just making sure you really need all of this. Thanks!
I apologize, I’m not strictly an iOS/mobile developer, but my understanding is as follows:
The -ObjC flag tells the linker to load all object files in a library which define either an Objective-C class or a category. This allows the creation of Objective-C static libraries house definitions of categories on other existing classes. A category is kind of “dynamically” added method to an existing class and its added at load time, not compile time(disclaimer: probably not a fully correct definition.) The framework I want to wrap defines a category on a class contained within Apple’s Foundation framework. So, everything does build and compile, but without that flag, the category isn’t loaded correctly and a runtime exception results, effectively disabling the framework and its functionality.
OK, many thanks for explanation! I’ll read some more about it and make sure we’ll investigate what’s the best way of supporting this.
Thanks Michael! Just to re-iterate, too, -ObjC isn’t the only flag necessary for this framework to run correctly. I don’t want to give the impression that the -ObjC is the only stopper, there. Also, as I mentioned I’m not really an iOS dev, so, there could be a lot more out there that 3rd party frameworks are requiring.
Thank you for your report. We were not able to investigate this on the engine version you reported, but there have been many version changes to UE4 since this question was first posted. With a new version of the Engine comes new fixes and it is possible that this issue has changed or may no longer occur. Due to timetable of when this issue was first posted, we are marking this post as resolved for tracking purposes. If you are still experiencing the issue you reported in the current engine version, then please respond to this message with additional information and we will investigate as soon as possible. If you are experiencing a similar, but different issue at this time, could you please submit a new report for it.