libnl on macOS and iOS - ios

I'm trying to migrate a Linux/Android C app to macOS/iOS.
I have this problem, this app uses libnl library some times, in the source code you can see includes like:
#include <linux/netlink.h>
#include <linux/rtnetlink.h>
#include <linux/if_tun.h>
These files are from libnl library, you can find information about this library here:
https://www.infradead.org/~tgr/libnl/doc/core.html#_introduction
I don't know what it's the equivalent in macOS and iOS. Maybe is the same but in another path?
Also I tried to download libnl library and add it to /usr/local/include but it have other dependencies, this is why that I think that I'm in the wrong way...
I found this guide https://developer.apple.com/library/content/documentation/Darwin/Conceptual/NKEConceptual/intro/intro.html#//apple_ref/doc/uid/TP40001858-CH225-SW1
But this means that I need to rewrite all parts of the code that uses libnl?
Any ideas?
Thanks in advance!

You will probably need to do some changes to code. A quick glance at the libnl docs shows that you might be able to use GDAsyncSocket.
https://github.com/robbiehanson/CocoaAsyncSocket
But without seeing your code, it's not possible to be sure.

Related

How to compile `.framework` file?

I searched through existing Stackoverflow questions related to this problem but didn't find any help to solve it.
So here's the problem:
I am trying to integrate .framework file into the project but it's giving me an error saying that module compiles with 4.0.3 can't be imported by swift 5.0 compiler.
I wanted to know how to compile that.framework file? so that it will become compilable to swift 5.0
Please help if you come across such a problem.
Note: .framework file is created by a third-party developer
If the framework you're trying to integrate is binary only, then your best option is to check with the 3rd party developer regarding their support for Swift 5.0.
In case there are sources available, you can try checking if there is any work being done in their repository (usually a separate branch), or you can try forking the sources yourself.
Note that with the source option, you'll have access to possibly unstable and untested code, and depending on the experience I'd be very careful in this case.

How do I navigate namespaces in MonoTouch / Xamarin for iOS?

This is an example of something that I have experienced a couple of times when working with MonoTouch:
I find a code example on the internet giving an example on how to use the NSUrl class. I try to add it to my code in Xamarin Studio. It is simple, except I can't find which using statement to use. I try to google, but no examples I find include the elusive using statement I am looking for. I find the the official Mac Developer Library NSUrl description, but it does not tell me much (or perhaps it tells me too much).
In general, how do you go about finding which using statement to use in a case like this? Is there a Xamarin documentation of this somewhere that I just can't find? I'm not looking for the specific namespace from the example, but how to go about finding it myself.
If it's an iOS API, it will always be
MonoTouch.<iOS Framework Name>
So if you found NSUrl, you should also be able to see that it is part of Apple's "Foundation" framework.
MonoTouch.Foundation
Of course, I would just recommend just letting the IDE figure it out for you.
Right-click (on NSUrl) -> Resolve -> "using MonoTouch.Foundation"

Embedding Mono on iOS

I want to embed mono into my iOS application. I do not want to use MonoTouch. I want to embed mono manually like this:
http://www.mono-project.com/Embedding_Mono
I've have done this successfully on windows, using the above guide and various online examples, here's a good Windows one:
https://github.com/inkdev/Embedded-Mono-Sample
However I'm having trouble getting started on iOS. I know it can be done, companies like Unity3d use it to power their game engine tech. I can't work out how to compile and link mono for iOS nor can I find any good instructions to do so. I've not found any help using search engines, they exclusively seem to turn up articles about MonoTouch (Xamarin's own commercial wrapper around embedding mono into iOS).
Here's a few more noteworthy links:
http://www.mono-project.com/Mono:ARM
http://web.archive.org/web/20090106023130/http://mono-project.com./Mono:Iphone
Is there somewhere I can get precompiled libraries and headers for Mono for iOS, so in my C code I can simply link and include?
Could someone provide and example of how to compile mono for iOS ARM CPUs?
MonoTouch provides a great wrapper around all of the iOS Objective C APIs, however you don't necessarily need all of that, as I understand it should be possible to compile and then embed mono yourself and then use pInvoke to call the few native functions you will need.
Any help would be greatly appreciated, ty!
While not exactly what you are asking for, iOS 7 has added support for scripting with JavaScript. Many people finding this post may want to use this new capability to achieve what you are attempting. Link
As Rolf said, you need to read Mono Licensing document first. Embedding mono on iOS requires special permission from Xamarin.
You need to change several build settings from XCode, and here's what I did.
Open (or Create) iOS project
Add libmonoboehm-2.0.a to your project(You can use another version of .a file)
It's in Library/Frameworks/Mono.framework/Versions/{version}/lib folder
Project -> Build Settings -> Header Search
Add path: /Library/Frameworks/Mono.frameworks/Versions/{version}/include/mono-2.0
Project -> Build Settings -> Library Search
Add path: /Library/Frameworks/Mono.frameworks/Versions/{version}/lib
And, code like this in your iOS application
#include <mono/jit/jit.h>
#include <mono/metadata/mono-config.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/environment.h>
// ....
const char* dllFile = "ABSOLUTE_PATH_TO_DLL_OR_EXE";
domain = mono_jit_init(dllFile);
mAssembly = mono_domain_assembly_open(domain, dllFile);
// ... Do whatever you want :)
Please remember. You need to get license from Xamarin when embedding mono on iOS.
Enjoy :)

Lexical or Preprocessor issue / xmlversion.h not found when using Sudzc/VTK in an iOS app

I've set up VES and am modifying the Kiwiviewer app in XCode 4.3.2. Kiwi builds and runs fine, so I'm now trying to set up Sudzc within my app (it works fine standalone). I've followed the tutorial here but at the point after modifying the headers, where his app builds and runs, mine instead comes up with a succession of errors. At first, it gives >150 errors all along the lines of:
Lexical or Preprocessor Issue
Invalid token at start of a preprocessor expression
Mostly pointing at the line
#include "xmlversion.h"
in a file tree.h, which is a part of vtkmodular/Utilities/vtklibxml2/include/libxml/tree.h.
Changing the " " to < > (which was suggested for a similar problem) instead gives another Lexical or Preprocessor Issue, this time that 'xmlversion.h' file not found - seemingly all in the file tree.h. The file's in my Project Navigator (and cmd-clicking on #include "xmlversion.h" does indeed load the file, so it understands it that way).
Presumably then the problem is with vtk having its own version of libxml2? If this is the case - what can I do about this? All of the errors I've looked at seem to originate from within soap handler classes, and eventually get through to "include < libxml/tree.h>" - which is then in the vtk directory shown above. I'm not really sure where to go from here - is it wrong to include the library that's added in the instructions? Can/should I modify the header paths? If this isn't the tree.h the rest of the code is looking for, where is it - a quick system search didn't find it?
Or am I completely off the mark?
Thanks in advance!
I got an answer from the VES Mailing List, link here. It ended up being as simple as removing the VTK version of libxml2, which it seems VES doesn't use. Hope this might be of use to someone!

iOS help: math.h? Where is this?

I am following a tutorial out of a book and in the .h file of where some of my code is, I have to type in: #import . Where is this file located? Is it part of some framework or do I have to download it somewhere? I've googled this and found a question about math.h on MacRumors, so I know that it has something to do with iOS programming and probably isn't specific to the book.
It's part of the SDK that you have already installed if you are doing iOS development. All you need to do is put the line
#import <math.h>
in your code. You don't need to download anything. You don't need to link against anything (the math library, libm, is part of libSystem on both iOS and OS X, and is linked by default).
Note that this has nothing to do with "iOS programming". <math.h> is part of the C standard library, not specific to any platform.
Have you tried this? Did you encounter a problem?
Well, it depends. In the tutorial you're following, if it imports that header like so:
#import "math.h"
That means it is in the user header search path. In other words, it's not a system library, but something the author created. If that is the case, you'll have to find it online, or maybe in the back of the book you're reading.
If the library instead appears like this:
#import <accelerate/math.h>
Then it's a system library(note the '< >' instead of quotes), in the accelerate framework (just an example, I don't know if there is a math.h in accelerate or not). The first part of the path of the import indicates the framework you'll find the header in.
If you change your question to include the full #import statement in the book, I can more accurately help you.

Resources