Cocoapods Link Error: __FBTweakIdentifier (with custom build configuration) #4

Closed
LeffelMania opened this Issue Mar 26, 2014 · 10 comments

Projects

None yet

6 participants

@LeffelMania

Trying to get set up with Tweaks, added the pod to my podfile:

pod 'Tweaks'

Got the FBTweakShakeWindow integrated and displaying 0 items (as expected), went to add my first tweak as such:

self.alpha = FBTweakValue(@"Category", @"Thing", @"Alpha", .6, 0.1, 1.0);

When I went to build I got a Linker Error:

Undefined symbols for architecture i386: "__FBTweakIdentifier"

I see the externs defined in FBTweakInline.m and FBTweakinlineInternal.h, but I can't get this resolved.

Any suggestions on what I might have missed or what the problem might be?

Many thanks.

@grp
Contributor
grp commented Mar 27, 2014

Hm, __FBTweakIdentifier is a macro so it shouldn't need to link. Let me try it and see if I can reproduce.

@LeffelMania

FYI my code works as expected when I drop in the source files directly into my project, so I'm leaning towards a Cocoapods config issue, but I don't know how to debug it really.

@szotyi
szotyi commented Mar 27, 2014

I have a similar issue, but I can run in simulator and on debugging device. When I want to archive for a testflight build (to send to customer for testing), then the Linker Error happens:

Undefined symbols for architecture armv7: "__FBTweakIdentifier", referenced

and also

Undefined symbols for architecture armv7s: "__FBTweakIdentifier", referenced

and also

Undefined symbols for architecture arm64: "__FBTweakIdentifier", referenced

I'm using cocoapods also and FB_WEAK_ENABLED is set to 1 in the Preprocessor Macros. One thing I found is that ARC is turned off in the build settings for the Pods-Tweaks target, but turning it on, didn't help.

@szotyi
szotyi commented Mar 27, 2014

Checked also without Cocoapods (just moved the FBTweak dir into the project) and everything builds fine. I agree with @LeffelMania on probably being a Cocoapods config issue.

@grp grp changed the title from Cocoapods Link Error: __FBTweakIdentifier to Cocoapods Link Error: __FBTweakIdentifier (with custom build configuration) Apr 2, 2014
@grp
Contributor
grp commented Apr 2, 2014

Investigated some at the Cocoapods task: CocoaPods/CocoaPods#1934

It seems to be a conflict between how Cocoapods projects are configured, how configurations are propagated, and the macros that Tweaks relies on. Still looking into how to best solve it.

@mokagio
mokagio commented Apr 16, 2014

@grpaul as @alloy explained in CocoaPods/CocoaPods#1934 the app project and the Pods project macros have to be in line. This is why sometimes when using custom build configurations Tweaks doesn't link, the macros used by the Pods project to compile Tweaks are different from the ones used by the app project.

I updated my example repo with a Podfile that compiles.

Wrapping it up:

  • If you are using a custom build configuration created by duplicating Debug and you want Tweaks enabled you are fine.
  • If you are using a custom build configuration created by duplicating Release and you don't want Tweaks enabled you are fine.
  • If you are using a custom build created by duplicating Debug but you don't want Tweaks enabled, you need to add FB_TWEAKS_ENABLED=0 to both your target and the pods one.
  • If you are using a custom build created by duplicating Release but you want Tweaks enabled, you need to add FB_TWEAKS_ENABLED=1 to both your target and the pods one.

In case you are not checking in your Pods/ directory, there are pros and cons to that, every time you run pod update or pod install the Pods project is regenerated and the FB_TWEAKS_ENABLED is be lost. To avoid that add this post_install hook to your Podfile

post_install do |installer_representation|
  installer_representation.project.targets.each do |target|
    if target.name == "Pods-TweaksBuildConfigurationsDemo-Tweaks"
      target.build_configurations.each do |config|
        if config.name == 'QA'
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'FB_TWEAK_ENABLED=1']
        end
      end
    end
  end
end

What it does is adding FB_TWEAK_ENABLED=1 for the build configuration named QA to the Pods project.

@grp
Contributor
grp commented Apr 16, 2014

Should be good to close this now, but nice to have a great explanation to point anyone to who hits this issue!

@grp grp closed this Apr 16, 2014
@mokagio
mokagio commented Apr 16, 2014

Maybe we can update the README?

On Wednesday, April 16, 2014, Grant Paul notifications@github.com wrote:

Closed #4#4?utm_campaign=website&utm_source=sendgrid.com&utm_medium=email
.


Reply to this email directly or view it on GitHubhttps://github.com/facebook/Tweaks/issues/4?utm_campaign=website&utm_source=sendgrid.com&utm_medium=email
.

Giò

"Be a yardstick of quality. Some people aren't used to an environment
where excellence is expected" S.J.

@ktraunmueller

Note: FB_TWEAK_ENABLED, not FB_TWEAKS_ENABLED

@AlexeyDemedetskiy

It looks like with Cocoapods v0.38.2 hook should look like

post_install do |installer_representation|
    installer_representation.pods_project.targets.each do |target|
        if target.name == "Tweaks"
            target.build_configurations.each do |config|
                config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'FB_TWEAK_ENABLED=1']
            end
        end
    end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment