You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gomobile Bind生成库(PIE禁用/i386架构)iOS Pod校验报错求助

Fixing Illegal Text-Relocation Error for Gomobile-Built iOS Frameworks in Cocoapods

Got it, let's tackle this illegal text-relocation error you're hitting with pod lib lint—I've seen this exact issue with gomobile-built frameworks before. The root cause is that iOS's strict release-time build checks (which pod lib lint enforces) block code that directly references read-only data segment addresses, and some low-level Go code (like sync/atomic.Value.Store here) can trigger this if the framework isn't built with the right flags.

Here's your step-by-step fix:

1. Update Go & Gomobile to the Latest Versions

The Go team has fixed a ton of iOS linker quirks in recent releases, so start by making sure you're on a modern Go version (1.18+ recommended) and have the latest gomobile tooling:

# Update gomobile to the latest version
go install golang.org/x/mobile/cmd/gomobile@latest
# Re-initialize gomobile to sync with your current Go setup
gomobile init

Verify your Go version with go version to confirm it's up to date.

2. Rebuild Your Framework with Linker Flags to Block Text Relocations

When you run gomobile bind, add specific linker flags to force the system linker to reject text relocations. Replace your build command with this:

gomobile bind -target ios \
  -ldflags="-linkmode=external -extldflags=-Wl,-no_text_relocs" \
  -o Client.framework \
  github.com/your/actual/go/package/path
  • -linkmode=external tells Go to use the system's linker instead of its internal one (better for iOS compatibility)
  • -extldflags=-Wl,-no_text_relocs instructs the system linker to throw errors if it detects text relocations (which ensures we avoid the lint failure)

3. Tweak Your Podspec Config

Make sure your .podspec has these critical settings to align with iOS release requirements:

Pod::Spec.new do |s|
  s.name             = 'FoobarSDK'
  s.version          = '0.1.0'
  s.summary          = 'Your Foobar SDK for iOS'
  s.homepage         = 'https://your-homepage.com'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'You' => 'your@email.com' }
  s.source           = { :path => '.' }
  s.platform         = :ios, '12.0' # Adjust to your minimum supported iOS version
  s.static_framework = true # Key fix: Static frameworks avoid dynamic linking relocation issues
  s.vendored_frameworks = 'Client.framework'

  # Compile settings to pass iOS release checks
  s.pod_target_xcconfig = {
    'OTHER_LDFLAGS' => '-ObjC', # Ensures all Go symbols are linked properly
    'ENABLE_BITCODE' => 'YES', # Set to NO if you don't need bitcode, but recommended for App Store
    'VALID_ARCHS' => 'arm64 x86_64', # Restrict to supported architectures
    'CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER' => 'NO', # Suppress irrelevant warnings
  }

  s.user_target_xcconfig = {
    'VALID_ARCHS' => 'arm64 x86_64',
  }
end

4. Verify Your Framework's Architectures

Double-check that your framework includes both device (arm64) and simulator (x86_64) architectures—missing one can cause hidden linker issues:

lipo -info Client.framework/Client

You should see output like: Architectures in the fat file: Client are: x86_64 arm64. If not, re-run the gomobile bind command with explicit targets:

gomobile bind -target ios/arm64,ios/x86_64 \
  -ldflags="-linkmode=external -extldflags=-Wl,-no_text_relocs" \
  -o Client.framework \
  github.com/your/actual/go/package/path

5. Re-Run pod lib lint

Now try the lint command again. For more debugging info, add --verbose:

pod lib lint --verbose

If you get non-critical warnings that you want to skip, add --allow-warnings:

pod lib lint --allow-warnings

That should resolve the text-relocation error and get your pod through the lint check!

内容的提问来源于stack exchange,提问作者Matti

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:30:23