Converting static framework to dynamic - xcode

I want to convert static iOS framework (https://github.com/comScore/ComScore-iOS-watchOS-tvOS/tree/master/ComScore/iOS) into dynamic.
> clang -arch x86_64 -dynamiclib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk -lc++ -F . -framework ComScore -ObjC -o ComScoreDynamic
This command is successful, however, there is a problem with symbol visibility.
When I check symbols in the original framework it is around 4k of public symbols:
> nm -gU ComScore.framework/ComScore | wc -l
4387
In dynamic version only very few of them:
nm -gU ComScoreDynamic
0000000000114af8 S _OBJC_CLASS_$_SCORCommonUtils
0000000000114940 S _OBJC_CLASS_$_SCORCrossPublisherIdSourceValue
0000000000114a08 S _OBJC_CLASS_$_SCORHTTP
0000000000114990 S _OBJC_CLASS_$_SCORHelper
0000000000114aa8 S _OBJC_CLASS_$_SCORObfuscation
0000000000114a80 S _OBJC_CLASS_$_SCORReachability
0000000000114918 S _OBJC_CLASS_$_SCORUniqueId
0000000000114b20 S _OBJC_METACLASS_$_SCORCommonUtils
00000000001149e0 S _OBJC_METACLASS_$_SCORCrossPublisherIdSourceValue
0000000000114a30 S _OBJC_METACLASS_$_SCORHTTP
0000000000114968 S _OBJC_METACLASS_$_SCORHelper
0000000000114ad0 S _OBJC_METACLASS_$_SCORObfuscation
0000000000114a58 S _OBJC_METACLASS_$_SCORReachability
00000000001149b8 S _OBJC_METACLASS_$_SCORUniqueId
00000000001166b0 D __ZTINSt3__117bad_function_callE
00000000000d5d60 S __ZTSNSt3__117bad_function_callE
All other symbols marked as internal (t and s markings).
How can I keep symbols external?
UPDATE:
Looks like this can be similar problem: Export an `OBJC_CLASS` from one static lib as part of another
Problem is that symbols in static lib are exported as private_extern and there is no way to preserve them in dynamic library.

The public symbols in the comScore framework are marked private external. This can be seen with the nm utility and looking for the SCORAnalytics class:
nm -m ComScore/iOS/ComScore.framework/Versions/A/ComScore |grep _OBJC_CLASS_\$_SCORAnalytics
Shows:
---------------- (LTO,DATA) private external _OBJC_CLASS_$_SCORAnalytics
This means the symbol can only be linked against once. When Cocoapods performs a pre-link for secondary ('transitive') dependencies, these symbols lose their extern attribute. The idea here is to prevent public symbols from a dependency from leaking into those of another library. The problem is that, for Swift projects, they aren't fully resolved until the final app link; by that point they're no longer available.
The real issue is that the comScore library is a static framework. The best solution would be for comScore to release it as a dynamic framework, but these are only supported by iOS 8 and above; comScore insists on support all the way back to iOS 6. I know.
For now, my solution is to include the comScore framework directly in our Cocoapod and vend it within the Podspec, allowing it to work with both Obj-C and Swift projects. The downside is I have to manually update our Cocoapod every time comScore releases a new version. There would also be symbol conflicts if another pod included comScore, but since our pod is a metrics aggregator that logs to several backends, it's likely to be the only metrics component in use. YMMV.

Related

How do I bind to a system framework with Xamarin.Mac?

I'm in the proces of making an app for interacting with smartcards.
For that I'd like to use the CryptoTokenKit Framework which is standard on a Mac (located at /System/Library/Frameworks/CryptoTokenKit.framework).
This link says that it's possible to bind frameworks in a Mac project:
https://developer.xamarin.com/guides/cross-platform/macios/native-references/
I've created an ApiDefinition.cs file and a StrucsAndEnums.cs file using the following sharpie command:
sharpie bind -framework ./CryptoTokenKit.framework -sdk macosx10.13 -o ~/CryptoTokenKitBinding
I can't find any info on the internet how to implement the above mentioned files and start using the framework.
Create a Xamarin.Mac binding project within a solution.
Add a NativeReference to:
/System/Library/Frameworks/CryptoTokenKit.framework
Bind it using sharpie:
sharpie bind \
-o CryptoTokenKitFramework \
-namespace CryptoTokenKit \
-sdk macosx10.13 \
-f /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CryptoTokenKit.framework
There is a mismatch between the binding project template and the output of sharpie, so you can either delete ApiDefinition.cs and add ApiDefinitions.cs or just overwrite the template created one:
mv CryptoTokenKitFramework/ApiDefinitions.cs CryptoTokenKitFramework/ApiDefinition.cs
There will be a number of attributes like (versions will change across them):
[Watch (4,0), TV (11,0), Mac (10,12), iOS (10,0)]
As these are private frameworks on iOS, Watch, TV, so strip those platforms out. Leave the Mac attribute and the original version:
[Mac (10,11)]
Note: PlatformAttribute is obsolete but sharpie is still using it (assuming backwards version compatibility(?)), so you can use Introduced if you really want to clean up the build output:
[Introduced (PlatformName.MacOSX, 10, 11, PlatformArchitecture.Arch64)]
There will be a few [Verify] attributes that have to be reviewed/corrected. i.e. TKSmartCardUserInteraction.Cancel and TKSmartCardSlot.MakeSmartCard should both be methods not properties.
Example / Generated:
// -(TKSmartCard * _Nullable)makeSmartCard;
[NullAllowed, Export ("makeSmartCard")]
[Verify (MethodToProperty)]
TKSmartCard MakeSmartCard { get; }
Corrected:
// -(TKSmartCard * _Nullable)makeSmartCard;
[NullAllowed, Export("makeSmartCard")]
TKSmartCard MakeSmartCard();
Fix the rest of the [Verify] attributes and compiler errors, there are a bunch of bad method signatures, pointers, return types, etc.. that are generated and need corrected.
Note: TO make your life easier, make sure that you are using the latest Sharpie version:
Version: 3.4.0
SHA1: c12859dac8d43121b5a9ed866a0db8409f9df817
URL: https://dl.xamarin.com/objective-sharpie/ObjectiveSharpie-3.4.0.pkg

How to run gcov on test application with Nuttx OS on STM discovery board?

Setup:
Toolchain: gcc-arm-none-eabi-5_2-2015q4-20151219
Target: STM429i-disco board
I want to run gcov and get real time report generated in target as per below link:
https://mcuoneclipse.com/2014/12/26/code-coverage-for-embedded-target-with-eclipse-gcc-and-gcov/
First, sucessfully have compiled my code (POSIX compliant NUTTX OS) with -fprofile-arcs & -ftest-coverage flags & got generated the .gcno files for my src files.
second, sucesfully have linked with -fprofile-arcs flags enabled and using the libgcov.a file (part of the toolchain) and the final binary is generated.
Now, I dont know what changes are needed in my test application to invoke gcov, generate report & dump report.
Another problem is, gcov functions are with HIDDEN attribute in libgcov.a as below.
9: 00000000 4 FUNC GLOBAL HIDDEN 1 __gcov_flush
9: 00000000 4 FUNC GLOBAL HIDDEN 1 __gcov_init
so, I could not invoke as I need.
Any inputs in getting the .gcda file generated would be of great help.
Can you look for gcov_exit instead? It is similar to __gcov_flush. Typically, it's one of gcov_exit and __gcov_flush that would be there and you can use any.
In case this is not there or is also hidden, you can use this approach which I tried for one of my projects. I picked (and modified for various reasons) the implementation of gcov_exit from gcc source code (of version matching my toolchain) (available at https://github.com/reeteshranjan/libgcov-embedded) and plugged it in my project. With everything else remaining the same (the compiler flags etc.), I was able to then break into gcov_exit and follow the rest of the approach in the blog link you have mentioned.

osx - WebRTC linkage issue

I'm trying to integrate WebRTC in one OSX Desktop application and I'm getting some errors when I try to link with webRTC library. The issue is:
Undefined symbols for architecture x86_64:
"_AVMediaTypeMuxed", referenced from:
cricket::GetAVFoundationVideoDevices(std::vector<cricket::Device, std::allocator<cricket::Device> >*) in libWebRTC-arm64-debug.a(libjingle_media.macdevicemanagermm.o)
This tell me that I have not defined this symbol in my libjingle_media.a, wich is true according with it:
$ nm libjingle_media.a | grep _AVMediaTypeMuxed
warning: /Applications/Xcode64.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm: no name list
U _AVMediaTypeMuxed
I have built WebRTC using this flags:
GYP_DEFINES="build_with_libjingle=1 build_with_chromium=0 libjingle_objc=1 OS=mac target_arch=x64"
GYP_GENERATORS="ninja"
GYP_GENERATOR_FLAGS="$GYP_GENERATOR_FLAGS output_dir=out_mac"
and of course with ninja, running previously gclient runhooks. Any idea about what is happening with this?
To solve this issue, you need to use a particular framework that implements the function, in this case a framework called AVFoundation

What is a simple way to play a .wav file in Nim on OSX?

I am trying to play a wav file in a very simple program that looks like this, currently attempting to use nim-csfml:
import csfml_audio
var alarmsong = newMusic("alarm.wav")
alarmsong.play()
but it appears to be relying on the existence of libcsfml.audio, and while my program compiles just fine, when I try to actually run it I get an error
| => ./alarm
could not load: libcsfml-audio.so
(I have a libcsfml-audio.dylib instead, being that I used the OSX shared libraries for csfml/sfml)
Is there some other way to play a .wav file in Nim?
Edit 1:
After the PR made by #def-, I now get a different, slightly more comforting error, which is probably due to some poor understanding of how nim deals with shared libraries:
| => ./alarm
could not load: libcsfml-audio.dylib
I added path = "/usr/local/lib" to my nim.cfg file, but it didn't seem to be affect anything. I also exported $LD_LIBRARY_PATH="/usr/local/lib" (/usr/local/bin is where libcsfml-audio.dylib is.), and tried compilation through
nim c alarm.nim --clib:/usr/local/lib/libcsfml-audio.dylib
Thanks for the help!
This program would just exit immediately; you need to keep it alive while the sound plays. Append this to the program:
import csfml_system
while alarmsong.status == SoundStatus.Playing:
sleep 100.milliseconds
For nim-csfml to work you'll need SFML 2.1 and CSFML 2.1. Also, it seems that nim-csfml is actually broken for Mac OS X, so I've made a pull request with a fix: https://github.com/BlaXpirit/nim-csfml/pull/4
Other modules that could play sound are sdl_mixer, sdl2/audio and allegro5.
As an OSX-only alternative without using any libraries, by calling the afplay binary:
import osproc
discard execProcess("afplay", ["file.wav"])
Edit1:
When Nim reports "could not load: libcsfml-audio.dynlib" that could also mean that one of the dependencies of that library are missing or in a wrong version. Especially SFML 2.2 doesn't work with CSFML 2.1. Make sure libsfml-audio.dynlib is in your LD_LIBRARY_PATH as well. If that doesn't work either, you could try to compile and run a regular C CSFML example like this one: https://gist.github.com/def-/fee8bb041719337c8812
Compile it with clang -o mainpage -lcsfml-graphics -lcsfml-audio -lGL -lGLEW mainpage.c to see the errors/warnings about missing libraries.

How to build mpich2 with sctp network module in linux?

What configure options a should use to compile mpich2 (ver 1.1.1p1 or 1.2.1p1) with sctp ?
In my try there is a error when linking cpi.c (small example).
/home/op02/mpiopt/sctp/lib/libmpich.a(ch3u_rma_sync.o)(.text+0x20a7): In functio
n `MPIDI_Win_post':
: undefined reference to `PMPI_Group_translate_ranks'
/home/op02/mpiopt/sctp/lib/libmpich.a(ch3u_rma_sync.o)(.text+0x21bd): In functio
n `MPIDI_Win_post':
: undefined reference to `PMPI_Group_free'
/home/op02/mpiopt/sctp/lib/libmpich.a(ch3u_rma_sync.o)(.text+0x25c4): In functio
n `MPIDI_Win_complete':
: undefined reference to `PMPI_Group_translate_ranks'
....
My options was
../mpich2-1.1.1p1/configure --enable-fast=O1 \
--host=x86_64-unknown-linux-gnu \
--target=x86_64-secret-linux-gnu \
--with-device=ch3:sctp --with-pm=hydra \
--with-cross=x8664secret.cross --disable-f77 --disable-f90 \
>conf.log 2>&1
with x8664secret.cross being an output of getcross.c program. Host, target, and this file are here to force a cross-compilation. (it is a requirement for this build)
Is sctp in mpich2 in active state and can it be compiled?
Does sctp network module support cross-building?
Try 1.3.1 instead. I see that Brad Penoff committed a couple of small changes to the build system since 1.2.1p1 was released, so it may be in better shape now. Alternatively, try using (the rather old) MPICH2 1.0.8, where I believe things were still working.
If the cross-compile step is what's really causing the problem and you still need to solve this problem, you can get more interactive support from mpich-discuss#lists.anl.gov. We can dig in over there instead.

Resources