iphone objective c static library within static library - objective-c

I am trying to distribute static lib that contain static lib (google adMob).
In my test application that uses the static library, it crashes when trying to access the static library within the static library.
Any ideas on how to distribute static library that contain static library?
10x
Tamir

There is no such thing as a "static library within a static library". A static library is just a container of object files. And they are all equal.
You have two options:
Distribute your own library and the third party library as two separate files. The final project then needs to include both libraries.
Merge the two libraries, i.e. create a library that contains all your object files and the object files of the third party library. Have a look at the man pages for ar, libtool, ranlib etc. for more information.
Option 1 seems the easier one. If your static library has additional dependencies on dynamically linked libraries (such as an iOS framework or libiconv), then you'll have to provide instructions about how to add these dependencies anyway.
(I don't quite understand when and how your test app crashes. You'd have to provide more information such as the full error message and the stack trace. Normally, I'd expect that the app doesn't even build since it can't find all dependencies.)

Related

With Kotlin Native, building a windows exe, can I bundle libraries ( dlls ) into the exe?

Let's say I want to build a simple windows exe that does HTTP requests with curl.
( See example: https://github.com/JetBrains/kotlin-native/tree/master/samples/curl ).
The example above works, but in order for the exe to run, it needs to find libcurl-4.dll, either in the local dir, or e.g. in the installation dir ( e.g. C:\msys64\mingw64\lib ).
I would like to ship just the exe file, without having to provide the dll files separately. Is it possible to build the exe file with all the things it uses from the library (and transitive dependencies...) bundled into the exe file?
(This question is about if I can do this with a Kotlin 1.3.61 Native project, and how.)
I'm studying Kotlin too and it took many hours until I realize how to handle def file, includes and static library.
I made an example of how to use static library (curl with gzip and SSL support compiled with mingw) on kotlin-native. This way you dont need to dll files to be supplied with your app
https://github.com/carlosrafp/Libcurl-Kotlin-Native-standalone
On libcurl.def file you can see:
headers = curl/curl.h // path to curl header
libraryPaths = src/nativeInterop/cinterop // path to your static library
staticLibraries = libcurl.a // the static library
linkerOpts.mingw = -lws2_32 -lwldap32 // linking dependences
I based on the nice post of jonnyzzz:
https://jonnyzzz.com/blog/2018/10/29/kn-libcurl-windows/
You need to build the static libraries using mingw (libcurl, gzip) and msys2/mingw(openssl) to use with kotlin-native compiler
You can definitely do this for a static library(see this), but not for the .dll. About the shared library bundling, I would just recommend you to see this question. It's about the same but a bit generalized.

How to use dylib file in application?

I have created lib.dylib dynamic library. I want to use that library in my application.
What are the Build setting and build phase settings are required?
Steps to use the library in objective-c.
so there are 2 ways...
1) if the Dyld is available at link time, then you just link against it. (in Xcode you add it to the link build phase of the target you are building.)
if using a framework: The headers will end up in the header search path so you can #import <framework/header.h> them.
2) if it isn't then you will need to open the dynamic library with dlopen, then you read in each function directly... this is much more of a specialty task, like dealing with a plug-in architecture.
there are some tricky thinks if you are supplying the dynamic lib then there are issues with the library install path being relative to the executable... but you will just have to tackle them if you hit them (start by googling #rpath)

CMake- Difficulties building static library

So I have been trying to build libarchive for a couple of days now, following this guide and many other threads: https://github.com/libarchive/libarchive/wiki/BuildInstructions
I want a static library with LZMA, zlib and bzip2 support. I got static versions of these too (lib's)
I just cant get it to work properly. Ive used CMAKE to generate the make files for VS2010 and NMAKE. With both of these options the thing compiles just fine, but when i try to use the archive_static.lib generated, in my project I get plenty of unresolved externals. Compiling the .dll version of the library works without unresolved externals, but then it starts asking for zlib.dll, bzip2.dll etc, which i dont have and dont want to use.
I think i need to set some flags with cmake, but im not sure how to do that.
Any help is greatly appreciated.
http://www.libarchive.org/
I can't be sure if that's what happening here, but please bear in mind, that when linking binaries into a static library, its external dependencies do not necessarily get embedded into it, that means you might need to provide thet static libraries on which your program indirectly depends through libarchive, namely LZMA, zlib and bzip2 in your case, explicitly.
Furthermore there's some confusion on windows when it comes to linking static vs dynamic, for in both cases you provide a .lib file, so it is very easy to mix things up and provide the dynamicaly linked .lib, instead of the static version. If you do that, the linker may refuse to link your program (that notably happens with boost), or may link just fine and then, at the time of execution, the OS will require the respective .dll's.

Difference of DLL and LIB extension

I know that LIB files are static link - when I use it in my project, on compiling, all it's content added to my file. DLL is dynamic - loaded to memory and all the projects that needs it, can use it.
Why should I use DLL instead of LIB (and vice versa?
How can I compile my code to DLL (or LIB)?
Thank you
According to this wiki page, .lib files are used in conjunction with .dll, which means that you don't have to prefer one over another.
For example, kernel32.dll, the primary dynamic library for Windows'
base functions such as file creation and memory management, is linked
via kernel32.lib.

How to compile multiple objective C files into one library?

Is it possible to compile multiple objective C (.m) files into one .a library? The resulting code would be used in iPhone apps via XCode.
If yes, do you have any links to a tutorial, or can you paste a Makefile?
You do not need a tutorial. Just start a new project, select iOS / Framework & Library / Cocoa Touch Static Library and start adding a files. That is it. Compiled lib will have all the files in place. Provide headers to consumers for all included files so they will know what's inside. It is pretty simple, let me know if you need an additional clarification.