Is it possible to add an LC_LOAD_DYLIB to a binary? There has been protection against DYLD_INSERT_LIBRARIES being used so I need another to load a dylib into an app
I open-sourced optool which does exactly this.
Related
Question stated simply in title. Here is my setup:
Building a dynamic framework that optionally links (weak link) to GoogleInteractiveMediaAds.framework. For apps that use my framework, GoogleInteractiveMediaAds is an optional dependency, and the framework will work fine without it. This is currently working.
However the problem arises when attempting to rebuild from bitcode, as typically happens when exporting an Ad Hoc build with "Rebuild from Bitcode" selected. The bitcode compile process fails with:
ipatool failed with an exception: #<CmdSpec::NonZeroExitException: $/Applications/Xcode.app/Contents/Developer/usr/bin/bitcode-build-tool ...
And looking deeper into the log file I find the error description:
Failed to resolve linkage dependency MyFramework arm64 -> #rpath/GoogleInteractiveMediaAds.framework/GoogleInteractiveMediaAds: Could not resolve #rpath in #rpath/GoogleInteractiveMediaAds.framework/GoogleInteractiveMediaAds from MyFramework
error: GoogleInteractiveMediaAds not found in dylib search path
Note: GoogleInteractiveMediaAds.framework does include bitcode.
Obviously this error is avoiding by not selecting "Rebuild from Bitcode". If I were to answer my own question, I'd say, no, it looks like when compiling from bitcode, you cannot use weakly linked frameworks. Simply from the fact that the bitcode compilation step is trying to link to a framework which isn't included in the app target. However I haven't been able to find any official documentation surround using weak linking with bitcode, or any relevant StackOverflow answers about it, so I'm not sure if I'm missing something or if there is some relevant compiler/linker settings that I am missing to get this to work.
In your case, you will need to wait for the fix in framework itself.
We've got similar issue while distributing our framework, which I described here and I just wan't to share results of our investigation, because seems that no-one has published their results.
No needs to distribute without bitcode. Long story short, there were LLVM instrumentation included, which prevents AppStore processing. I've written a whole blog about XCode 12 and BigSur issues with XCFramework.
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.
I am getting all these errors I have no idea why I hope you can help me guys.
I have included "avformat.h" in bridging header
I have included all frameworks/libraries needed too
Make sure you have all required includes and they are included inside extern, you may be seeing name mangling going on. Read this https://trac.ffmpeg.org/wiki/Including%20FFmpeg%20headers%20in%20a%20C%2B%2B%20application
This is one possibility if you have already made sure that libraries are in path and included.
My SDK uses a libssl.a library, but when I give it to a customer to use my SDK, they also uses a version of libssl.a and is causing duplicate symbol. Is there anyway to allow both to coexist?
Thanks
One option would be to rebuild libssl with a custom prefix on each symbol. I wrote a script for this purpose, which you can find here.
A simpler option might be to not link to libssl.a and require the customer to link to it instead. To do this, simply #import libssl's headers as usual, but leave libssl.a out from the link binary with libraries phase. The linker does not attempt to resolve symbols unless the target is an executable, so you will be able to compile a static library on this way without issues.
I'm adding adMob provide by google to my iOS app and I'm stuck on this part of the installation:
Add -all_load under Other Linker Flags in the project build info
If I add that flag, then another third party library breaks giving me the error message:
ld: duplicate symbol _vw_chartype_table_p in /Users/josh/ Projects/app/libs/libvt_universal.a(vw_ctype-3279EF26D0C25F3A.o) and / Users/josh/Projects/app/libs/ libvt_universal.a(vw_ctype-34AB9EC0B46D954C.o) for architecture i386
Is there any way to use the adMob library without using -all_load? For example, I've tried -force_load $(SOURCE_ROOT)/adMob/libGoogleAdMobAds.a
but
ld: file not found: /Users/USERNAME/Desktop/latest/bbbb/APPNAME/adMob/libGoogleAdMobAds.a
The reason Google suggests using -all_load is that they are using categories in their code, and Objective-C libraries with categories are not properly loaded by the llvm linker (well that was the case in 4.3 xcode, not sure about 4.4 with the newer clang).
So, I guess if you are brave you can try to just remove the all_load flag. It should build fine. If the bug is NOT fixed, what will happen is when you run your code, it will crash, since none of the categories the library uses will have been loaded. This might be a good thing to do in any case, as your project should build, and if it does not you can fix those problems first.
What I do suggest you do is use -force_load, which has llvm load the categories in the adMob library (among other things). To use it you MUST have a fully qualified path (ie starts at '/') to the library. Obviously if you use Terminal and run:
ls -l /Users/USERNAME/Desktop/latest/bbbb/APPNAME/adMob/libGoogleAdMobAds.a
its going to fail. So enter the proper path - hard coded - for now to just see if you can get the project to first build, then run. If it does you can later figure out what is the appropriate $(VAR) to use to find it inside your project.
I am trying to integrate a large legacy C++ library with an iOS app. We are able to build and run on device but we are not able to archive the app. Archiving fails with the following error.
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip failed with exit code 1
I did a -v on the strip and get a series of warnings similar to
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip: symbols referenced by relocation entries that can't be stripped in: /MyApp/DerivedData/SmartMusic_iPad/Build/Intermediates/ArchiveIntermediates/MyApp/IntermediateBuildFilesPath/UninstalledProducts/libMyLib-iOS.a(MyWhatever.o)
It is not clear if this message is a warning or the reason for the failure. There are no other indications of problems in the strip output. Any clues?
Under build settings for the static library target, select NO for 'deployment postprocessing' and 'strip debug symbols during copy'. It is compiled code so it doesn't need symbols stripped.
I was experiencing the same error ('usr/bin/strip failed with exit code 1') and this fixed it for me.
In my case I added the following to my library Target build settings and started working fine:
Dead Code Stripping: NO
Strip Debug Symbols During Copy: NO for all configurations
Strip Style: Non-Global Symbols
The default Strip Style in Xcode is All Symbols, which is okay for an executable but for a library you need to set this to Non-Global Symbols as global symbols must be be preserved.
Since stripping is only done as part of the deployment post processing, debug builds are usually not affected by this option as for them the setting DEPLOYMENT_POSTPROCESSING is usually set to NO. But when archiving, you create a release build and here DEPLOYMENT_POSTPROCESSING is set to YES by default and thus you need to have the correct strip style set.
There are different options to strip (see manpage) and I think you'll want to use the -r option. You can set the type of stripping to perform from within the Xcode project settings. See if you can relate the options in Xcode with the options in the manpage.
I have same your problem, but I edit DEPLOYMENT POSTPROCESSING to NO but it doesn't work.
I just went to Build Phases tab in my target, and in Copy Bundle Resources I removed Foundation.framework, and then I add Foundation.framework into Link Binary With Libraries, it works for me!
Hope that will be solve your problem!
What worked for me was when I decided to fix another issue in Xcode 10.1, my simulator hadn't been booting up and I ignored until I really needed it, running the command below helped fix this issue
sudo chmod 1777 /private/tmp
I fixed this error by freeing up more space
On Xcode 11.5, I solved this by setting Strip Linked Product to No in Build Settings of the Framework target.
In our project we have used InjectHotReload library to enable hot reload mechanism. This library caused for strip error. We removed from pod and also removed other linker flags which needed when setup InjectHotReload.
May someone see this and fix problem.
Good luck.
Try setting
STRIP_INSTALLED_PRODUCT to No for your target(one for which you are getting error) build setting.
if this does not work then try below along with above option
Dead Code Stripping: NO
Strip Debug Symbols During Copy: NO for all configurations
Strip Style: Non-Global Symbols
Hope this will solved your problem.