zweigraf / face-landmarking-ios

👦 Basic face landmarking on iPhone with Dlib via Swift & ObjC++
481 stars 125 forks source link

dlib link error iOS #7

Closed dmwesterhoff closed 8 years ago

dmwesterhoff commented 8 years ago

Hi, wondering if you can speak or provide guidance to this specific link time issue I'm having

_USER_ERROR__missing_dlib_all_source_cpp_fileORinconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives

This happened when I tried to port the libdlib.a and wrapper classes to my project- I have attempted to change all build settings in my project to look like the example project. Any ideas?

dmwesterhoff commented 8 years ago

Believe to have tracked down the issue, it was due to a cocoapods flag that was using DEBUG=1 as a preprocessor macro

willard-yuan commented 8 years ago

When I compiles the project, I also face the problem. Anyone knows how to deal with the problem?

ld: warning: ignoring file /Users/willard/codes/swift/dlib_app/face-landmarking-ios/DisplayLiveSamples/lib/libdlib.a, missing required architecture i386 in file /Users/willard/codes/swift/dlib_app/face-landmarking-ios/DisplayLiveSamples/lib/libdlib.a (2 slices)
Undefined symbols for architecture i386:
  "_USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives_", referenced from:
      __GLOBAL__sub_I_DlibWrapper.mm in DlibWrapper.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
zweigraf commented 8 years ago

Don't use the simulator :) The camera won't work anyway. This error just means that the Dlib library is not compiled for the simulator (i386).

dboyliao commented 7 years ago

I encountered the same issue when I build dlib from source and drag the static library into my xcode project. I finally managed to fix this error and I think it is good to have a step by step approach here for those who are not familier with compilation/linking. See here for instructions of building dlib for iOS.

The origin of this linking error comes from dlib/threads/threads_kernel_shared.h. It's good to have a look on the comments in it. To fix the bug, do as following:

  1. Go to Build Settings > Apple LLVM - Custom Compiler Flags > Other C Flags and enter -DDLIB_JPEG_SUPPORT -DDLIB_NO_GUI_SUPPORT -DNDEBUG -DDLIB_USE_BLAS -DDLIB_USE_LAPACK
    • these are flags which defines some macros for the preprocessor and will include different features in the compiled dlib static library.
  2. Once you have libdlib.a compiled, drag it into your xcode project.
  3. Go to the Build Settings in your xcode project and search for Preprocessor Macros.
    • As @zweigraf said in the README.md, make sure you use the same macros as the c flags you use for compiling libdlib.a.
    • As an example here, you should set Preprocessor Macros in your xcode project as DLIB_JPEG_SUPPORT DLIB_NO_GUI_SUPPORT NDEBUG DLIB_USE_BLAS DLIB_USE_LAPACK if you follow step 1.
    • Note that the -D is removed for each flags.
  4. Then you have it! You should be able to compile and link successfully.
scm-ns commented 7 years ago

For me what ended up solving the issue was building Dlib under Release mode, by specifying it in the scheme. Thanks a lot for all the help!

torrtuga commented 7 years ago

@dboyliao Hi, I did add for both Custom Compiler Flag as well as Preprocessor Macros. But am still getting the same "_USER_ERROR__missing_dlib_all_source_cpp_file__OR__inconsistent_use_of_DEBUG_or_ENABLE_ASSERTS_preprocessor_directives_", referenced from: error.

I just added one line : #include <dlib/image_processing.h> to check for dlib. And this line gave me the error.

kennylugo commented 7 years ago

The error still continued in my case, until I realized that I had made a silly mistake. I had added the preprocessor macros but only on debug mode, I fixed it by making sure that it was inputed on both Debug and Release. screen shot 2017-08-28 at 2 31 31 pm

GLinnik21 commented 7 years ago

Same here

PavanMore commented 7 years ago

I am facing same issue tried all solution's above but I have stuck for flag -std=c++11, when I set it in build setting in my xcode project I get the more errors and I cannot build library without that flag because it is mandatory there. So its like blocker , I am trying to build 19.4 dlib version. Any help will be appreciated.

WimVriend commented 5 years ago

Same here: that nasty bugger did not want to go...

Finally I realised that it is also possible to use dlib without using cmake, as mentioned under chapter Compiling C++ Examples Without CMake. I added /all/source.cpp to my project and removed libdlib.a. Of course, I also had to add the correct path to the Header Search path (1 for dlib itself and one for libjpeg)

Hope this helps anyone!