dyld[87074]: Symbol not found: ___cxa_current_primary_exception
Referenced from: <3A292F4E-DC5A-371D-9312-8CFE435E1BB3> /private/var/containers/Bundle/Application/FC803DBE-C59A-41AC-99F8-643B1D3D3285/xxxx.app/xxxx
Expected in: <7D909FFB-D2D0-369B-BC19-9EA4279A9944> /usr/lib/libc++.1.dylib
Symbol not found: ___cxa_current_primary_exception
Referenced from: <3A292F4E-DC5A-371D-9312-8CFE435E1BB3> /private/var/containers/Bundle/Application/FC803DBE-C59A-41AC-99F8-643B1D3D3285/xxxx.app/xxxx
Expected in: <7D909FFB-D2D0-369B-BC19-9EA4279A9944> /usr/lib/libc++.1.dylib
dyld config: DYLD_INSERT_LIBRARIES=/usr/lib/libLogRedirect.dylib:/usr/lib/libMainThreadChecker.dylib:/usr/lib/libRPAC.dylib:/usr/lib/libViewDebuggerSupport.dylib
如果非Pod,可手动添加
Other Linker Flags中添加:
-Wl,-force_load,$(SDKROOT)/usr/lib/libc++abi.tbd
-Wl,-weak_library,$(SDKROOT)/usr/lib/libc++.tbd
-Wl,-weak_library,$(SDKROOT)/usr/lib/libc++.1.tbd
如果Pod,则把工程里Pods下的名字复制到下面 Podfile post_install钩子处
# 处理post_install钩子,修改XCConfig文件
post_install do |installer|
# 定义所有需要修改的XCConfig文件路径
xcconfig_paths = [
'Pods/Target Support Files/Pods-Unity-iPhone/Pods-Unity-iPhone.release.xcconfig',
'Pods/Target Support Files/Pods-Unity-iPhone/Pods-Unity-iPhone.releaseforprofiling.xcconfig',
'Pods/Target Support Files/Pods-Unity-iPhone/Pods-Unity-iPhone.releaseforrunning.xcconfig',
'Pods/Target Support Files/Pods-Unity-iPhone/Pods-Unity-iPhone.debug.xcconfig'
]
# 定义要添加的配置
linker_flags = [
'-Wl,-force_load,$(SDKROOT)/usr/lib/libc++abi.tbd',
'-Wl,-weak_library,$(SDKROOT)/usr/lib/libc++.tbd',
'-Wl,-weak_library,$(SDKROOT)/usr/lib/libc++.1.tbd'
].join(' ')
# 处理每个XCConfig文件
xcconfig_paths.each do |xcconfig_path|
if File.exist?(xcconfig_path)
puts "修改配置文件: #{xcconfig_path}"
modify_xcconfig(xcconfig_path, linker_flags)
else
puts "警告: 未找到配置文件 #{xcconfig_path}"
end
end
end
# 修改XCConfig文件的辅助方法
def modify_xcconfig(file_path, linker_flags)
# 读取文件内容
content = File.read(file_path)
# 检查OTHER_LDFLAGS设置是否存在
if content.match?(/OTHER_LDFLAGS\s*=/)
# 已有设置,确保$(inherited)存在并添加新标志
content.gsub!(/OTHER_LDFLAGS\s*=\s*(.*)/) do |match|
current_flags = $1.strip
new_flags = current_flags
# 确保$(inherited)存在
unless current_flags.include?('$(inherited)')
new_flags = '$(inherited) ' + current_flags
end
# 添加新标志,避免重复
unless current_flags.include?(linker_flags)
new_flags += " #{linker_flags}"
end
"OTHER_LDFLAGS = #{new_flags}"
end
else
# 没有设置,添加完整行
content += "\nOTHER_LDFLAGS = $(inherited) #{linker_flags}\n"
end
# 写入修改后的内容
File.open(file_path, 'w') do |file|
file.write(content)
end
puts "已更新 #{file_path} 文件"
end