how to build DLIB for iOS
Asked Answered
O

4

20

I'm trying to build DLIB for an iOS project. Running the cmake results in a libdlib.a and a load of .o files.

When I add the library to an Xcode project I get warning that the library hasn't been built for arm64.

My question is two-part:

  1. How can I build DLIB for iOS (I tried cmake **path_to_source** -DCMAKE_OSX_ARCHITECTURE="arm64" but it caused loads of errors e.g. unknown type name '__uint32_t'; did you mean '__uint128_t')?
  2. What is the purpose of all the .o files that get built when you run cmake? Do I need to include them in an Xcode project?
Ordovician answered 4/1, 2016 at 12:32 Comment(19)
Object files (*.o) are just bi-product of the build. And resulting libdlib.a is static library You're probably would like to use. What's Your Xcode version?Lefler
Im using the latest version 7.2Ordovician
The source i have is for linux/OSX so I'm not sure if it's possible to build for iOS?Ordovician
Yes it is that one this is the website. There are a load of makefiles in the examples folder. This is the compilation instructionsOrdovician
Thanks @ruslo I'll check it out.Ordovician
Thanks all, I am trying to build DLIB for IOS using CMAKE. I got error "pthread" not found. Can you tell how to build DLIB for iOS as Static Library.?Montalvo
@Montalvo have you installed all the dependencies and have the latest versions of Cmake and Xcode? I'm afraid I'll need more information to help you further.Ordovician
thanks for reply.How to install all dependencies for DLIB for IOS. I used Xcode 7.2 and IOS.cmake toolchain and make version is 3.2 .Can you send Xcode Project of DLIB or DLIB static lib for IOS.?Montalvo
You need libX11 and opencv and that's what I can remember off the top of my head. X11 you can install using the tool in utilities and you'll need to download opencv using homebrew. I can't send you the project unfortunately. It's a work one and I don't have the rights to it.Ordovician
Thanks for your reply. I am going install libX11 for IOS . Are you using DLIB CMakelist.txt for building DLIB for IOS.?Montalvo
x11 is able to build Mac OS X only. Then How to build X11 for IOS/Iphone Device.?Montalvo
You use cake to make the Xcode project and then Xcode to build for iOS. X11 gets bundled up in the binary but yes you can only use X11 related code on OS X.Ordovician
Thanks @RASS i builded DLIB for IOS. I created Xcode project and included source code and set X11 headers in header path from Mac OSX and then i builded the lib static lib for IOS. Am i followed steps are correct.?Montalvo
Sounds like you've got somewhere. You shouldn't have to include any more source code in the Xcode project, Cmake should do that for you.Ordovician
But when i used DLIB CMakelist from downloaded github link. I got CMake error "pthread" not found . Thats why I added source code in Xcode.? So if i install thread for Mac OS X and then CMake gives no error. Am i correct.?Montalvo
If you're not getting any errors and the library works then that's good. There are a lot of settings in the CMakeList, honestly I cant really tell any more without looking at your project.Ordovician
Thanks @RASS . Which DLIB commit you are used from Github.? and DLIB static lib is working slow speed .?Montalvo
I didn't download it from GitHub I downloaded it from here. Also you need to build in release configuration to speed it up. There are a also a load of instruction sets that can be activated (e.g. AAX) in the make file that speed up execution.Ordovician
Thanks @RASS. Let me check it out.Montalvo
O
20

I finally figured out how to do this:

Requirements

  • X11 (on a mac you can just open the X11 app and if X11 isn't installed it'll take you to the download).
  • Xcode
  • cmake (you can use home-brew for that)

Steps

  • In terminal make the lib-xx.xx/examples your root
  • Run:

    mkdir build

    cd build

    cmake -G Xcode ..

    cmake --build . --config Release

This will create a folder called dlib_build in which you can find an Xcode project that compiles the library. In the build settings of that Xcode project you can set the build architecture and SDK for any Xcode supported OS you like!

EDIT:

You have to include a lot of custom compiler flags and 3rd party libraries to get dlib to work in a project. Check out the examples.xcproject build settings.

Ordovician answered 28/1, 2016 at 10:33 Comment(19)
I did exactly like you said, Tho it gave me an xCode project that only complies on Mac(OSX). Am i missing something?Hannahhannan
Yea all you have to do is go into the build settings and change the supported platforms.Ordovician
@RASS hi! I also try to build my XCode app for iOS with dlib library, but I get a lot of problems due to architecture type(e.g. ld: building for iOS simulator, but linking against dylib built for OSX, file '/opt/X11/lib/libICE.dylib' for architecture x86_64). Did you used some architecture flags on the dlib building stage or on the XCode app building stage?Mclaren
@don-prog you can change the active architecture at the dlib build stage in the Xcode build settings. As default it is set to OS X but you can change it to iOS or simulator.Ordovician
@RASS have you used iOS toolchain for building dlib for iOS? I ask this because I have some problems with this. It would be very kind of you if you could give me some particular advices about dlib building stage for iOS. Maybe I even don't need to use iOS toolchain or something else?Mclaren
No I haven't used the toolchain for building it. There are quite a few things that you need to do to the makefile (optimisations) and then at the dlib Xcode build stage. Check out this project of mine hopefully it will help.Ordovician
@RASS thanks, this is a very detailed tutorial, all clear! But I got only a few problems with libs: ld: building for iOS simulator, but linking against dylib built for OSX, file XXXXX for architecture x86_64 where XXXXX: libjpeg.dylib, liblapack.dylib, libpng.dylib, libcblas.dylib, It is obvious, because it's really dylib for OSX but I'm building iOS project. Also I have ld warning: ld: warning: ignoring file /usr/local/lib/DLIB/iOS/libdlib.a, file was built for archive which is not the architecture being linked (i386): /usr/local/lib/DLIB/iOS/libdlib.a. How can I fix these issues?Mclaren
@don-prog it just seems like you need to change the architecture that you build dlib for. This needs to be done in the Xcode project that is generated when you build it. If i remember correctly you use the -G flag with cmake to use Xcode as the build tool.Ordovician
@RASS are you sure? Because the problem not in the dlib, but in the libjpeg.dylib, liblapack.dylib, libpng.dylib, libcblas.dylib. And if you are sure, which command I need to use for this?Mclaren
@don-prog have you set your header search paths correctly? I used home-brew to install lib jpeg and open cv and I put the DLIB headers in the include folder also. I also used Cocoapods to install opencv for iOS.Ordovician
@RASS yes, I think I have set header search paths correctly. By the way, I checked libraries with which I have a problems using file x.dylib command and got an output which says that these libraries built only for i386 and x86_64 architecture, so I can't use them on arm64, armv7, armv7s. But I also checked libraries with which I HAVEN'T problems(e.g. /usr/lib/libpthread.dylib) and got the same output. So now I totally confused. Can you say how you installed libjpeg, liblapack, libpng, libcblas for use on iOS? And what should I do with linker warning which says about ignoring file libdlib.a?Mclaren
@RASS now I got rid of warning about libdlib.a, this was because I forgot to change iOS Device to iPhone simulator. But I still get errors due to lapack, jpeg, png, cblas libs. Nobody can help me, so any your suggestions will be very useful! Thanks.Mclaren
@RASS I am really sorry for the disturbance, but I still have no progress with this issue. I asked a few question on the SO, tried to post topics on the Apple forum but it's really gave nothing! I very need your help with this misunderstanding. Can you provide some advices about it? If you want I can pay for this using Upwork or using some another way, this is no problem. I really very need to know how I can do this. Regards.Mclaren
@don-prog the best thing to do might be for you to let me clone your project and see what needs to be done. Is it on github?Ordovician
@RASS many thanks for your response! I uploaded my test project to the github, hope this will help... This project causes ld: building for iOS simulator, but linking against dylib built for OSX, file XXXXX for architecture x86_64 error. Also in this project I get this error if I use only libdlib: ld: in /usr/local/lib/DLIB/iOS/libdlib.a(entropy_decoder_kernel_2.o), building for iOS simulator, but linking in object file built for OSX, for architecture x86_64 P.S. By the way, I need to set up Build Settings for project or for target?Mclaren
@don-prog the issue is not with the project you gave me it's with the installed dependencies, including DLIB. you said you were having problems with libjpeg and libpng e.t.c. how did you install them? Are they in the right directories? I'm sure you're aware that Xcode uses the library search paths to locate the lib files and the header search paths to get the includes.Ordovician
@RASS sorry, now I have added the dependencies and paths where I have originals of these libraries. I think I have these libraries by default, but I also tried to use libjpeg and libpng which have been installed using homebrew, should I have to use some other way? How you did it? Also I use full paths of dependencies(as in your github project), so I think it's does not metter which library search paths I use.Mclaren
@don-prog I was using OpenCV quite a lot and libjpeg and libpng are dependencies of OpenCV which I installed using home-brew. The error you have: /usr/local/lib/DLIB/iOS/libdlib.a ... building for iOS simulator, but linking in object file built for OSX, for architecture x86_64 is definitely a fault at the dlib build stage. Firstly did you build dlib for the simulator because it uses a different architecture than iOS devices? Also it seems you've built dlib for OS X which is a different architecture again.Ordovician
@RASS wow... I think I did it! The problem was due to using iPhone-simulator instead of real iPhone. I switched target to iPhone and successfully built project with dlib and all of "problematic" libs. Many thanks for your support and one more time sorry for the this stupid issue :D I just have little experience in such iOS details.Mclaren
B
10

To compliment RASS's answer, I am attaching screenshots showing how to change this to and from an iOS and OSX lib

After opening the project,

  1. Select the project file from the project navigator
  2. Select the dlib target all the way down the bottom
  3. Select 'Build Settings'
  4. Expand 'Base SDK' drop down

enter image description here

  1. Select either iOS or macOS (OSX)

enter image description here

I hope this helps some people out! gl

Bolanger answered 30/12, 2016 at 13:7 Comment(0)
T
0

Rob Sanders and mylogon already show how to build dlib for ios, here is how to use it:

  1. add libdlib.a to project, and add path to library search paths
  2. add all source to include directory(do not add to project), and add path to header search paths.
  3. add accelerate framework, which contains blas symbols.
  4. add preprocessor macros, from building settings, "custom compiler flag"/"other c flags". these macros make sure the header files match the lib.

    -DDLIB_JPEG_SUPPORT
    -DDLIB_NO_GUI_SUPPORT
    -DNDEBUG
    -DDLIB_USE_BLAS
    -DDLIB_USE_LAPACK
    
Tightfisted answered 13/11, 2018 at 8:46 Comment(0)
J
0

I have erros

Could not build the precompiled application for the device.
Error (Xcode): Undefined symbol: dlib::entropy_decoder_kernel_2::get_target(unsigned int)

Error (Xcode): Undefined symbol: dlib::entropy_decoder_kernel_2::set_stream(std::__1::basic_istream<char, std::__1::char_traits<char> >&)

Error (Xcode): Undefined symbol: dlib::entropy_decoder_kernel_2::decode(unsigned int, unsigned int)

Error (Xcode): Undefined symbol: dlib::entropy_decoder_kernel_2::entropy_decoder_kernel_2()

Error (Xcode): Undefined symbol: dlib::entropy_decoder_kernel_2::~entropy_decoder_kernel_2()

Error (Xcode): Undefined symbol: dlib::base64::base64()

Error (Xcode): Undefined symbol: dlib::base64::~base64()

Error (Xcode): Undefined symbol: dlib::base64::decode(std::__1::basic_istream<char, std::__1::char_traits<char> >&, std::__1::basic_ostream<char, std::__1::char_traits<char> >&) const

Error (Xcode): Linker command failed with exit code 1 (use -v to see invocation)```
Jephum answered 7/4, 2023 at 14:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.