How to Remove Warning: "-pie being ignored. it is only used when linking a main executable"

enter image description here

Since updating to Xcode10 and Swift 4.2, I always get this build time warnings in my pod. what do I have to do to remove these warnings?

I have tried to delete derived data, clean and build project, but it doesn't work :(

I find someone asks the same question here https://github.com/Alamofire/Alamofire/issues/2624 and there is an answer from Jon Shier, but I still can't resolve the issue after removing the previous xcworkspace and update cocoapods, I have not implemented to change "Generate Position-Dependent Executable" setting because I can't find it. please share if you can find the solution of this issue :)


Solution 1:

Setting "Generate Position-Dependent Code" to Yes does not feel like the right fix. Position-independent is preferred. Non-app targets like frameworks and libraries will always be position independent anyway, hence the warning.

The warning shown is a linker message and the other setting in @Marcpek's screen shot seems more suitable: "Linking > Generate Position-Dependent Executable". QuickHelp shows this is the LD_NO_PIE setting.

Generate Position-Dependent Executable LD_NO_PIE setting

Even though this inherits No anyway from the OS defaults I tried setting it to No again in my CocoaPod targets explicitly and that seemed to work, fixing the linker warning.

Any project settings you make will be lost the next time you run pod install so edit the Podfile to make the change permanent. Add config.build_settings['LD_NO_PIE'] = 'NO' into post_install phase:

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['LD_NO_PIE'] = 'NO'
        end
    end
end

Solution 2:

What finally worked for me is to enable position-dependent code for the Pods project. I tried disabling warnings from pods and clearing (instead of enabling) the Generate Position-Dependent Code setting before but that didn't really work.

Disable -pie for Pods

To enable position-dependent code (and hence remove -pie, which is Position Independent Code), after opening the xcworkspace, go to the Pods project build settings (the settings for the whole Pods project, see screenshot), search for position and set the Generate Position-Dependent Code build setting to Yes.

Changing pie setting for Pods

Solution 3:

One option is to switch to linking pods as static libraries instead of frameworks. use_frameworks! was required when Swift didn't support static libraries, but now that it does, you can remove that line from your Podfile, pod install, and the warning should be gone.

More info on the history of use_frameworks: https://stackoverflow.com/a/49469205/8831