Duplicate symbol error when linking AdMob SDK in RubyMotion - ios

My RubyMotion project builds fine, but fails at the linking stage, specifically when linking against GoogleAdMobAds, with a "duplicate symbol" error:
Compile ./app/controllers/blahblah_view_controller.rb
# compiling here, everything is awesome, until...
Create ./build/iPhoneOS-6.1-Development/App.app
Link ./build/iPhoneOS-6.1-Development/App.app/APP
duplicate symbol _GAD_MD5 in:
/Users/edd/Projects/ProjectName/vendor/GoogleAdMobAdsSDK/libGoogleAdMobAds.a(md5.o)
/Users/edd/Projects/ProjectName/vendor/GoogleAdMobAdsSDK/libGoogleAdMobAds.a(gad_md5.o)
ld: 1 duplicate symbol for architecture armv7s
clang: error: linker command failed with exit code 1 (use -v to see invocation)
rake aborted!
Command failed with status (1): [/Applications/Xcode.app/Contents/Developer...]
/Library/RubyMotion/lib/motion/project/builder.rb:393:in `build'
/Library/RubyMotion/lib/motion/project/app.rb:72:in `build'
/Library/RubyMotion/lib/motion/project.rb:56:in `block (2 levels) in <top (required)>'
Tasks: TOP => build:device
(See full trace by running task with --trace)
It's worth noting this occurs only when building for device. It works fine running in the simulator. Relevant Rakefile line:
app.vendor_project('vendor/GoogleAdMobAdsSDK', :static)
This problem also occurs when including the SDK via CocoaPods.
Any suggestions?

After perusing support forums for Google's AdMob, I found this thread basically saying issues have been observed when linking against the AdMob SDK when passing the -force_load flag to ld. Nobody goes into any more detail than that, but whatever.
Browsing the source, I also found an undocumented config option for RubyMotion's vendor_project that can make its invocation of ld use simply -ObjC instead of -force_load for your vendored code, and apparently that's what was needed to make this compile for me:
app.vendor_project('vendor/GoogleAdMobAdsSDK', :static, force_load: false)
Voila. I unfortunately can't explain why this is only happening when building for a device (probably something to do with -force_load combining with arch flags somewhere deep in RubyMotion), so if anyone can offer any wisdom, please leave a comment here.

If you really need to use -force_load (too much conflicts on the project with -ObjC for example) you can do the following.
Get a hexa editor (0xED for example)
Open the static lib with it
Go to the last line
Change the name of the constant to something else
save
done!

Related

iOS/macOS app distribution failed while using framework after upgrading Xcode12 and macOS BigSur

We are unable to distribute our sample app which uses our framework as well as our users can't.
While archiving and distributing to AppStore, the app is rejected with the following message:
Invalid Bundle - One or more dynamic libraries that are referenced by your app are not present in the dylib search path. If your app contains bitcode, bitcode processing may have failed. Because of these errors, this build of your app will not be able to be submitted for review or placed on the App Store.
The framework contain the bitcode, or at least there's a BITCODE_GENERATION_MODE = bitcode build setting in our .xcconfig, which basically means, the Xcode will add -fembed-bitcode build flag to any clang invocation.
From here, we've started testing using Ad-Hoc builds, to speed up our trial and error attempts, which also fails while Rebuild from bitcode option is selected. Organiser shows the popup with the following contents:
ipatool failed with an exception: #<CmdSpec::NonZeroExitException: $ /Applications/Xcode.app/Contents/Developer/usr/bin/python3 /Applications/Xcode.app/Contents/Developer/usr/bin/bitcode-build-tool -v -t /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin --sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.2.sdk -o /var/folders/vz/b0jj0dms4014y5htfv93svfc0000gn/T/ipatool20201130-52097-13rj9hy/thinned-out/arm64/Payload/iosTest.app/Frameworks/SciChart.framework/SciChart --generate-dsym /var/folders/vz/b0jj0dms4014y5htfv93svfc0000gn/T/ipatool20201130-52097-13rj9hy/thinned-out/arm64/Payload/iosTest.app/Frameworks/SciChart.framework/SciChart.dSYM --strip-swift-symbols /var/folders/vz/b0jj0dms4014y5htfv93svfc0000gn/T/ipatool20201130-52097-13rj9hy/thinned-in/arm64/Payload/iosTest.app/Frameworks/SciChart.framework/SciChart
Status: pid 52150 exit 1
Stdout:
SDK path: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/
Logs provided isn't very informative, here is the snippet from IDEDistributionPipeline.log
-= Output =-
ld: warning: -sdk_version and -platform_version are not compatible, ignoring -sdk_version
Undefined symbols for architecture arm64:
"___llvm_profile_runtime", referenced from:
__hidden#25821_ in 0832.o
__hidden#25821_ in 0833.o
__hidden#25821_ in 0834.o
__hidden#25821_ in 0835.o
__hid
2020-11-30 16:19:17 +0000 den#25821_ in 0836.o
__hidden#25821_ in 0837.o
__hidden#25821_ in 0838.o
...
ld: symbol(s) not found for architecture arm64
Exited with 1z
Failed to compile bundle: /var/folders/vz/b0jj0dms4014y5htfv93svfc0000gn/T/SciChart6aun_sfs/SciChart.arm64.xar
Stderr:
from /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:2808:in `block in CompileOrStripBitcodeInBundle'
from /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:2747:in `each'
from /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:2747:in `CompileOrStripBitcodeInBundle'
from /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:3016:in `block in ProcessIPA'
from /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:2978:in `each'
from /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:2978:in `ProcessIPA'
from /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:3928:in `<main>'
2020-11-30 16:19:17 +0000 /Applications/Xcode.app/Contents/Developer/usr/bin/ipatool exited with 1
which after bunch of warnings shows the actual error at the end of file (I can't include full log, since it's too much of a raw text):
code = 1061;
description = "ipatool failed with an exception: #<CmdSpec::NonZeroExitException: ...
info = {
};
level = ERROR;
type = exception;
Not sure what to to do with this, I've tried different build settings options, nothing helped... Already contacted apple, but no feedback yet, and knowing them, we can wait far too long...
The strange part here, is if we include our .framework directly as a source code and then archive the app - everything works as expected. If we include it as XCFramework or just .framework, which is pre-built - it fails as described above.
I might miss something simple or obvious here, so please let me know if somebody have some insights on that matter.
Some system info:
macOS BigSur 11.0.1
XCode Version 12.2 (12B45b)
We've tried different combinations of macOS and Xcode, e.g.:
Catalina with Xcode 12
BigSur with Xcode 11
etc.
Any help is greatly appreciated.
Thanks.
Long story short, there were LLVM instrumentation included, which prevents AppStore processing. I've written a whole blog post about it here - https://blog.scichart.com/xcframework-xcode-12-and-bigsur-issues/
To sum up, here is a few required steps to make sure while creating XCFramework for distribution:
Using archive builds is a MUST, release build isn't enough
BUILD_LIBRARY_FOR_DISTRIBUTION must be set to YES
SKIP_INSTALL must be set to NO
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = NO to turn off GCC instrumentation and remove them from the binary
CLANG_ENABLE_CODE_COVERAGE = NO to turn off code coverage tools from the binary
Having all of the above helped to solve our preparing and distribution problem and hopefully save you some time if you happened to face same issues as we did.

GCM linker command failed with exit code 1: Apple-Mach-O Linker Error

What I have done after 2 days of reading stack overflow:
Keywords to problem:
"Apple-Mach-O Linker Error",
"libGGLCore.a(Clientanalytics.pb.o,Icore.pb.o,Jspb.pb.o,LogsAnnotations.pb.o
...)", "_OBJC_CLASS_$_GSDK_PBExtensionRegistry"
,"_OBJC_CLASS_$_GSDK_PBGeneratedEnumDescriptor" ....
I Don't use pod. Manually Download files from Github
So I am stuck. How do I solve the problem(s) displayed in the image below:
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Did you download all the dependent pods? To make GCM work, you need Google, GoogleCloudMessaging, GGLInstanceID, GoogleInterchangeUtilities, GoogleIPhoneUtilities, GoogleNetworkingUtilities, GoogleSymbolUtilities, and GoogleUtilities.
There could be various errors in your code as per your description. Some of the possibilities are:
1. Please read this
2. Importing QuartzCore in the project might fix the issue too.
3. Cleaning the project and restarting might help you too.
4. Changing the architecture of the project from armv6 to armv7 or arm64 could help too.
5. Moving the linked library of GCM to another folder also causes this issue. Please check it out too.

'warning: directory not found for option' error on build

All of a sudden my app has started giving me an error when I try to build it. This is the error I'm getting:
ld: warning: directory not found for option '-L/Users/user/Documents/Developer/Alton-Towers-Times/build/Debug-iphoneos'
ld: file too small (length=0) file '/Users/user/Library/Developer/Xcode/DerivedData/Mouse_Times_Florida-eqhrhnbxmmkxtahdghmnvehbzbgt/Build/Intermediates/Mouse Times Florida.build/Debug-iphonesimulator/Mouse Times Florida WatchKit Extension.build/Objects-normal/x86_64/SecondInterfaceController.o' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Only thing I've really done since I last managed to get it to run was changing the bundle IDs and I also changed the app name. I've tried a few things including deleting the derived data, but nothing seems to have helped.
Anyone have any ideas?
I solved this warning removing the following setting: "$(SDKROOT)/Developer/Library/Frameworks"
This options is located in Settings -> Build Settings -> Search Paths -> Framework Search Paths
Setting location
My project continues compiling and working fine, after removing this option.
Veladan answer helped me to sort out that issue on an iOS8 project freshly migrated to iOS9.
This worked fine on the main target of my project, but the warning lasted on the unit tests target, so in the end I edited directly the project.pbxproj file and modified the entries :
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
to :
FRAMEWORK_SEARCH_PATHS = "";

Error Cross Compiling: hidden symbol ... final link failed

I am getting the following error when compiling opencv with ffmpeg.
..../arm-none-linux-gnueabi/bin/ld: ../../bin/opencv_test_core: hidden symbol `__sync_val_compare_and_swap_4' in ..../arm-none-linux-gnueabi/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status
I have no idea what this means. How do I fix this?
Edit:
I am cross compiling for ARM using codesourcery's arm-2009q3 compiler.
I using cmake and make to compile.
Please check all the libraries that you use and go through this stackoverflow thread as well.
To me, I got the below error when I migrated my product to new GCC version (3.3.3 to 4.5.4)
hidden symbol `__clz_tab' in /../lib/gcc/mipsel-unknown-linux-uclibc/4.5.4/libgcc.a(_clz.o) is referenced by DSO
Later I found that one of the library that I tried to link was built using GCC 3.3.3. After building the other library under GCC 4.5.4, the 'hidden symbol' error disappeared.

Library not found for -llib. (clang: error: linker command failed with exit code 1 (use -v to see invocation))

I am working on a project that was previously done and uploaded on app store.When I run this app in Xcode 5.0 it is working fine but when I run this on Xcode Version 5.1.1 (5B1008) I am getting Linker error on both device and simulator.
Error Message- Library not found for -llib. (clang: error: linker command failed with exit code 1 (use -v to see invocation)).
I have searched a lot but I didn't get any thread about Library not found for -llib error. Is there anything I have to change in build settings to resolve this?
Look at the linker command line in detail for the -L options being used:
Then use Terminal or Finder to see if your libXXX.a file exists in those directories. If the library exists elsewhere then you need to configure your Library Search Paths:
However there several details which you have not provided in your question when using a library within an app:
Is the library built as part of the Xcode project/workspace (as in the first image)?
Is the library supplied by a third-party with binary (.a) and header files (as in the second image)?
TL;DR: I ran make in the wrong directory so the paths were messed up.
Problem:
>make
linking ../build/release/yubikey-personalization-gui
/usr/x86_64-suse-linux/bin/ld: cannot find -llib
...
I ran into this when compiling the Yubikey Personalisation Tool. I tracked down the -llib call in my Makefile which looked like this:
...
LINK = #echo linking $# && g++
...
LIBS = $(SUBLIBS) -L/usr/lib64 -L../lib/release -llib -lyubikey -lykpers-1 -lQtGui -L/usr/lib64 -L/usr/X11R6/lib -lQtCore -lpthread
...
$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS)
So it was setting a variable called LINK which would print "linking" and then call g++, which is the compiler.
Then it set the var LIBS which would hold the ominous -llib.
Then it composes and runs the command $(LINK) ... $(LIBS).
Which runs g++ with the parameter -llib.
And what does that do? Turns out -l<something> is telling the compiler to use the something-library. So it asks for the library called lib here. Which is strangely generic. I figured out that the sources came with a directory called lib/, which was at ../lib.
So starting make from a directory higher up fixed it.
You should remove libstdc++ from other linker flags in your xcode project
https://stackoverflow.com/a/53103383/1344237

Resources