2

I have a C lib and dll file from windows application. No source code with me. Is it possible to use that in an IOS application.

I have seen mixed responses and am confused. If we have source code , i think we need to create dylib and then we can use the same after including relevant header file.

Please share any expert ideas to guide me in right direction. Appreciate your help .

  • mia

4 Answers 4

5

Dynamic Libraries are not permitted on iOS to begin with, but above that, the DLL file format is not recognized by Darwin or the underlying XNU Kernel at all, as the binary format is different.

Windows APIs are not usable on the Darwin OS either (Both Mac OS X and iOS are wrappers around the basic Darwin OS). You will need to rewrite the code from the DLL to use the POSIX and/or Objective-C APIs and compile it as a static library to use it.

3
  • Thanks for the details. I saw details for .a files as Version 1.5 Mac OSX 64/32-bit Universal Binaries (for Intel, Snow Leopard/10.6 or later) of OpenJPEG library and codecs at code.google.com/p/openjpeg/downloads/list . Can i use that in IOS ? Basically my need is to use OPENJPEG2000 lib and decompress an image in IOS. Thanks for your help
    – mia
    May 23, 2012 at 6:31
  • Of course, if it works on Mac OS X and is a static library, it should work for iOS as well. If they provide the source code to it, you could manually recompile it (wouldn't take that long to do so) and it would run just dandy. May 23, 2012 at 7:19
  • stackoverflow.com/questions/9580420/… would help you out. May 23, 2012 at 7:20
3

You need to get a iOS compatible library, no other way around it. There are several reasons:

  • iOS doesn't support DLLs as they are windows format, but moreover, you can't use any dynamic library on iOS, as Apple restricts it.
  • DLLs are usually for intel CPUs, while iOS devices have ARM CPUs.
  • Most dlls are calling windows APIs - are you sure this one's not?
8
  • Incorrect; DLLs themselves are cross-platform: their binary format is different however. In this case, iOS is ARM-only, so a DLL from an intel CPU would not work. May 10, 2012 at 4:28
  • @Galaxas0 - do you say Mac OSX (lets say on intel CPU) is able to load DLLs and use them? This is new to me
    – MByD
    May 10, 2012 at 4:32
  • Thanks for the answer. I am trying to do OpenJpeg2000 decode and encode. This dll is for the same. In that case i dont think it will be using Windows APIs. So in case if i get the source code ( as it is open source ) , i can compile and use in IOS rt?
    – mia
    May 10, 2012 at 6:07
  • @mia - it is probably possible, but it might be complicated. Worth the shot though.
    – MByD
    May 10, 2012 at 6:08
  • Mac OS X and iOS are based upon the same underpinnings: Darwin and the XNU Kernel. The Mac OS X and iOS names refer to the interaction style and interface layer COMBINED with the XNU Kernel and Darwin OS. Even on an Intel CPU, Darwin cannot read DLL binaries. Read more about the Mach-O binary format, if you need more information. May 10, 2012 at 6:09
1

No. If you all you have is a compiled binary DLL, there is no way to use it on iOS. Unless you happen to have an ARM DLL for the upcoming Windows 8, your DLL contains either x86 or x86-64 machine code (or maybe IA64 if you have a lot of money), which absolutely will not run on iOS devices, which are all ARM architectures. Plus many more reasons.

If you have the source code, you can recompile it for iOS, either directly into your app, as a static library that can be linked in with your app, or as a dynamic library as part of a framework. But in all cases, you need to recompile it from source code using the iOS compiler.

3
  • Incorrect; DLL files themselves are not dynamic libraries loadable by the XNU Kernel or Darwin (the Mac OS X underlying OS), and dynamic libraries themselves are not permitted on iOS. May 10, 2012 at 4:30
  • I never said DLLs were loadable by the XNU Kernel or Darwin. I'm pretty sure that iOS does have dynamic libraries -- when you weak link against a framework, the OS tries to load that framework at runtime. Using weak frameworks is a common way of providing optional functionality on devices with more recent versions of the OS. But I think you're right on that last part -- AFAIK, Apple doesn't let you create your own dynamic libraries or frameworks, you can only use the ones they provide. May 10, 2012 at 23:18
  • My bad then, maybe 'incorrect' was a bit harsh. And you are correct- technically speaking, dynamic libraries do exist. The reason Apple won't let you load them is because they may be malicious (think the recent Flashback trojan), so Apple runs otool -l on all binaries and checks them for any non-Apple dylibs or .frameworks. May 10, 2012 at 23:53
1

You are going to have to recompile it as a static library (.a file). Apple doesn't allow dynamic libraries except for their own frameworks (so you can't compile it as a dylib).

2
  • DLLs are unrecognized as dynamic libraries at all on Darwin and the XNU Kernel- it's a Windows thing. May 10, 2012 at 4:28
  • @Galaxas0 I was referring to OP's comment on dylib
    – borrrden
    May 10, 2012 at 4:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.