twelve17 / openalpr-ios

Xcode Framework for the openalpr library
GNU General Public License v3.0
116 stars 35 forks source link

Failure in building leptonica (and others) - MacOS Sierra issues #30

Open imodude opened 7 years ago

imodude commented 7 years ago

The build_framework.rb managed to build the opencv2.framework, but fails when it comes to leoptonica....

Building leptonica for i386 from /Users/ian/Dev/openalpr-ios/openalpr-ios/work/leptonica-1.71 configure: error: in /Users/ian/Dev/openalpr-ios/openalpr-ios/work/leptonica-1.71': configure: error: cannot run C compiled programs. If you meant to cross compile, use--host'. See config.log' for more details bundler: failed to load command: bin/build_frameworks.rb (bin/build_frameworks.rb) RuntimeError: Child returned: pid 82080 exit 1 /Users/ian/Dev/openalpr-ios/openalpr-ios/lib/alpr/utils.rb:44:inexecute' /Users/ian/Dev/openalpr-ios/openalpr-ios/lib/alpr/utils.rb:74:in log_execute' /Users/ian/Dev/openalpr-ios/openalpr-ios/lib/alpr/package/automake.rb:147:indo_autoconf_build' /Users/ian/Dev/openalpr-ios/openalpr-ios/lib/alpr/package/automake.rb:58:in build_arch' /Users/ian/Dev/openalpr-ios/openalpr-ios/lib/alpr/package/base.rb:53:inblock in install' /Users/ian/Dev/openalpr-ios/openalpr-ios/lib/alpr/package/base.rb:52:in each' /Users/ian/Dev/openalpr-ios/openalpr-ios/lib/alpr/package/base.rb:52:ininstall' bin/build_frameworks.rb:69:in `<top (required)>'

Looking in the leptonica config.log, I see this:

dyld: mach-o, but built for simulator (not macOS) ./configure: line 2878: 82300 Abort trap: 6 ./conftest$ac_cv_exeext configure:2880: $? = 134 configure:2887: error: in `/Users/ian/Dev/openalpr-ios/openalpr-ios/work/leptonica-1.71': configure:2889: error: cannot run C compiled programs.

Any clues appreciated - I'm fairly new to ruby and brew and downloading frameworks.

Thanks, Ian

CAJazzer commented 7 years ago

I experienced the same when building leoptonica. I ran xcode-select --install just to make sure I had the latest command line tools for Xcode 8.1 on Sierra 10.12.1 (this was recommended when "cannot run C compiled programs" error is reported)

Error snippet: Building leptonica for i386 from /Users/justme/xcode/openalpr-ios/work/leptonica-1.71 configure: error: in /Users/justme/xcode/openalpr-ios/work/leptonica-1.71': configure: error: cannot run C compiled programs. If you meant to cross compile, use--host'. See config.log' for more details bundler: failed to load command: ./build_frameworks.rb (./build_frameworks.rb) RuntimeError: Child returned: pid 85403 exit 1 /Users/justme/xcode/openalpr-ios/lib/alpr/utils.rb:44:inexecute' /Users/justme/xcode/openalpr-ios/lib/alpr/utils.rb:74:in log_execute' /Users/justme/xcode/openalpr-ios/lib/alpr/package/automake.rb:147:indo_autoconf_build' /Users/justme/xcode/openalpr-ios/lib/alpr/package/automake.rb:58:in build_arch' /Users/justme/xcode/openalpr-ios/lib/alpr/package/base.rb:53:inblock in install' /Users/justme/xcode/openalpr-ios/lib/alpr/package/base.rb:52:in each' /Users/justme/xcode/openalpr-ios/lib/alpr/package/base.rb:52:ininstall' /Users/justme/xcode/openalpr-ios/bin/build_frameworks.rb:69:in `<top (required)>'

Brew Config: HOMEBREW_VERSION: 1.1.0-23-g9889007 ORIGIN: https://github.com/Homebrew/brew HEAD: 988900709913d9c46e80a3493db0b9dcbff8264d Last commit: 8 hours ago Core tap ORIGIN: https://github.com/Homebrew/homebrew-core Core tap HEAD: 7c3884edb2e7e1baadd6556385017f9c5caaadcb Core tap last commit: 2 hours ago HOMEBREW_PREFIX: /usr/local HOMEBREW_REPOSITORY: /usr/local/Homebrew HOMEBREW_CELLAR: /usr/local/Cellar HOMEBREW_BOTTLE_DOMAIN: https://homebrew.bintray.com CPU: octa-core 64-bit haswell Homebrew Ruby: 2.0.0-p648 Clang: 8.0 build 800 Git: 2.9.3 => /Applications/Xcode.app/Contents/Developer/usr/bin/git Perl: /usr/bin/perl Python: /usr/bin/python Ruby: /Users/justme/.rvm/rubies/ruby-2.1.2/bin/ruby Java: 1.7.0_71 macOS: 10.12.1-x86_64 Xcode: 8.1 CLT: 8.1.0.0.1.1476494586 X11: N/A

Thanks for help!

Anarchid commented 7 years ago

The issue with building Leptonica on Sierra seems to be that in older versions of OSX you could compile for the iOS Simulator using the native OSX stuff. On Sierra you have to cross-compile for the Simulator.

I was able to work around this and get Leptonica to build by removing the condition at https://github.com/twelve17/openalpr-ios/blob/master/lib/alpr/package/automake.rb#L124.

However, now i'm stuck at the tesseract step, again with the Simulator:

Building tesseract for i386 from /Users/User/Documents/openalpr-ios/work/tesseract-3.03
configure: WARNING: using cross tools not prefixed with host triplet
configure: WARNING: Training tools WILL NOT be built because of missing pango library.
configure: WARNING: Try to install libpango1.0-dev package.
configure: WARNING: Training tools WILL NOT be built because of missing cairo library.
configure: WARNING: Try to install libcairo-dev?? package.
bundler: failed to load command: bin/build_frameworks.rb (bin/build_frameworks.rb)
RuntimeError: Child returned: pid 90598 exit 2
  /Users/User/Documents/openalpr-ios/lib/alpr/utils.rb:44:in `execute'
  /Users/User/Documents/openalpr-ios/lib/alpr/utils.rb:74:in `log_execute'
  /Users/User/Documents/openalpr-ios/lib/alpr/package/automake.rb:147:in `do_autoconf_build'
  /Users/User/Documents/openalpr-ios/lib/alpr/package/automake.rb:58:in `build_arch'
  /Users/User/Documents/openalpr-ios/lib/alpr/package/base.rb:53:in `block in install'
  /Users/User/Documents/openalpr-ios/lib/alpr/package/base.rb:52:in `each'
  /Users/User/Documents/openalpr-ios/lib/alpr/package/base.rb:52:in `install'

Suggest renaming ticket to include all Sierra build problems.

Anarchid commented 7 years ago

Relevant: https://github.com/swiftlyfalling/SQLiteLib/issues/9#issuecomment-250539478

CAJazzer commented 7 years ago

Yes, thank you, same experience here where it dies on i386 tesseract build

Anarchid commented 7 years ago

I have also tried skipping i386 and x86_64 builds. This succeeds to built tesseract, but fails at assembling openalpr itself.

wicheda commented 7 years ago

I've been experiencing the exact same issues regarding Sierra, does anyone with a deeper knowledge then me know of a potential solution to get openalpr built? Thanks in advance.

staticdreams commented 7 years ago

I'm in the same boat :( Fail to compile for i386

Anarchid commented 7 years ago

Here's the list of steps that got me an openalpr-ios that works on device: 1) Remove i386 and x86_64 lines from constants.rb (for both platforms and targets). This costs you the ability to run the lib on simulator, but now tesseract and leptonica will compile for actual devices.

2) Change the code signing parameters in iOS.cmake because Sierra refuses to accept unsigned builds:

--- a/etc/cmake/Toolchains/iOS.cmake
+++ b/etc/cmake/Toolchains/iOS.cmake
@@ -200,7 +200,7 @@ set(CMAKE_MACOSX_BUNDLE YES)
 # https://public.kitware.com/Bug/view.php?id=15329
 message(STATUS "Disabling code signing for ALPR iOS framework")
 SET(CMAKE_XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED NO)
-SET(CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "Don't Code Sign")
+SET(CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM "TENLETTERCODE")

3) Apply openalpr config from https://github.com/twelve17/openalpr-ios/issues/28#issuecomment-240298692

staticdreams commented 7 years ago

@Anarchid thank you. This worked for me!

wicheda commented 7 years ago

Amazing, this worked for me too, thanks very much @Anarchid

CAJazzer commented 7 years ago

Worked great! Thank you Anarchid.

CAJazzer commented 7 years ago

Did I miss a step? Trying to build AlprSample after adding frameworks and following specific ReadMe directions and getting errors. This is after getting successful builds of the 4 frameworks:

ld: warning: ld: warning: ignoring file /Users/userdir/xcode/openalpr-ios/AlprSample/tesseract.framework/tesseract, missing required architecture x86_64 in file /Users/userdir/xcode/openalpr-ios/AlprSample/tesseract.framework/tesseract (3 slices)ignoring file /Users/userdir/xcode/openalpr-ios/AlprSample/leptonica.framework/leptonica, missing required architecture x86_64 in file /Users/userdir/xcode/openalpr-ios/AlprSample/leptonica.framework/leptonica (3 slices)

ld: warning: ignoring file /Users/userdir/xcode/openalpr-ios/AlprSample/openalpr.framework/openalpr, missing required architecture x86_64 in file /Users/userdir/xcode/openalpr-ios/AlprSample/openalpr.framework/openalpr (3 slices)
Undefined symbols for architecture x86_64:
  "alpr::Alpr::setTopN(int)", referenced from:
      -[PlateScanner init] in PlateScanner.o
  "alpr::Alpr::isLoaded()", referenced from:
      -[PlateScanner init] in PlateScanner.o
      -[PlateScanner scanImage:onSuccess:onFailure:] in PlateScanner.o
  "alpr::Alpr::recognize(unsigned char*, int, int, int, std::__1::vector<alpr::AlprRegionOfInterest, std::__1::allocator<alpr::AlprRegionOfInterest> >)", referenced from:
      -[PlateScanner scanImage:onSuccess:onFailure:] in PlateScanner.o
  "alpr::Alpr::Alpr(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
      -[PlateScanner init] in PlateScanner.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Anarchid commented 7 years ago

Undefined symbols for architecture x86_64:

This looks like you're building for Simulator, or you have obtained an actual iOS device that runs on x86, or you have enabled the "build for all architectures" option in your project.

You cannot run the lib on x86 if you have not built it for x86, and my workaround works around the x86 build failure by skipping that build - as the fine print says:

This costs you the ability to run the lib on simulator, but now tesseract and leptonica will compile for actual devices.

If you want to run on Simulator or an x86 device, you'll have to actually solve the x86 build failure on Sierra, rather than bypass it as i have done.

CAJazzer commented 7 years ago

Yes, missed that. Works great.

ghost commented 7 years ago

Have tried following all the comments on this thread which has resolved a couple of the issues I was having, however I still cannot get openalpr to compile. This is the error I am getting, does anyone have any ideas?

Michaels-MacBook-Pro:openalpr-ios-dev michaelbowyer$ sudo bundle exec ./bin/build_frameworks.rb options: {} Package opencv2 is already installed. Skipping build. Package leptonica is already installed. Skipping build. Package tesseract is already installed. Skipping build. Building openalpr for armv7 from /Users/michaelbowyer/Documents/Development/OpenALPR-iOS-Dev/work/openalpr bundler: failed to load command: ./bin/build_frameworks.rb (./bin/build_frameworks.rb) RuntimeError: Child returned: pid 18622 exit 1 /Users/michaelbowyer/Documents/Development/OpenALPR-iOS-Dev/lib/alpr/utils.rb:44:inexecute' /Users/michaelbowyer/Documents/Development/OpenALPR-iOS-Dev/lib/alpr/utils.rb:74:in log_execute' /Users/michaelbowyer/Documents/Development/OpenALPR-iOS-Dev/lib/alpr/package/alpr.rb:112:inbuild_arch' /Users/michaelbowyer/Documents/Development/OpenALPR-iOS-Dev/lib/alpr/package/base.rb:53:in block in install' /Users/michaelbowyer/Documents/Development/OpenALPR-iOS-Dev/lib/alpr/package/base.rb:52:ineach' /Users/michaelbowyer/Documents/Development/OpenALPR-iOS-Dev/lib/alpr/package/base.rb:52:in install' /Users/michaelbowyer/Documents/Development/OpenALPR-iOS-Dev/bin/build_frameworks.rb:84:in<top (required)>'`

Thanks.

sashakid commented 7 years ago

Why if it helps (I mean https://github.com/twelve17/openalpr-ios/issues/30#issuecomment-261890050) nobody updates the main README? It's a pain to build openalpr, I did it twice and in both cases I googled a lot because I can't remember all the steps that were helpful but that are missing in main README.

twelve17 commented 7 years ago

@sashakid You can update the README. PRs are welcome.

emrosenf commented 7 years ago

For those still having trouble, I was able to build for all platforms including i386 and x86_64. The build was extremely difficult. The key was commenting out a line in thetesseract-3.03/api/Makefile. The line to comment out is:

am__append_9 = -lrt

I cannot tell you why the rt library is not found, but commenting out this line allowed the build to proceed. Unfortunately, I was unable to figure out how to get the Makefile to generate without this line, so I had to go in and edit the Makefile while it was building ...

Because of the difficulty, I have included the final .framework files in my library, react-native-openalpr. Feel free to clone the repo and use them.

GTMYang commented 6 years ago

Still failed!

bundle exec ./bin/build_frameworks.rb options: {} Package opencv2 is already installed. Skipping build. Building leptonica for armv7 from /Users/luoyang/openalpr-ios/work/leptonica-1.71 configure: WARNING: if you wanted to set the --build type, don't use --host. If a cross compiler is detected then cross compile mode will be used configure: WARNING: using cross tools not prefixed with host triplet bundler: failed to load command: ./bin/build_frameworks.rb (./bin/build_frameworks.rb) RuntimeError: Child returned: pid 46968 exit 2 /Users/luoyang/openalpr-ios/lib/alpr/utils.rb:44:in execute' /Users/luoyang/openalpr-ios/lib/alpr/utils.rb:74:inlog_execute' /Users/luoyang/openalpr-ios/lib/alpr/package/automake.rb:147:in do_autoconf_build' /Users/luoyang/openalpr-ios/lib/alpr/package/automake.rb:58:inbuild_arch' /Users/luoyang/openalpr-ios/lib/alpr/package/base.rb:53:in block in install' /Users/luoyang/openalpr-ios/lib/alpr/package/base.rb:52:ineach' /Users/luoyang/openalpr-ios/lib/alpr/package/base.rb:52:in install' /Users/luoyang/openalpr-ios/bin/build_frameworks.rb:69:in<top (required)>'

OgrePet commented 6 years ago

@GTMYang I've encountered the same issue and here is all steps that helped me to build this framework

  1. Made all changes described here https://github.com/twelve17/openalpr-ios/issues/30#issuecomment-261890050

  2. Fixed system() calls in leptonic library as was mentioned here https://github.com/libpd/pd-for-ios/issues/19#issuecomment-334133540 here is a patch that can be applied to leptonica’s src folder(that you can find after downloading in work folder) (it is pretty dirty but looks like it works in result) https://gist.github.com/OgrePet/516236d70028310b55861405e4c35b4c

  3. Upgraded tesseract to version 3.04 because it wasn’t building with iOS 11 (there were some errors that might be warnings previously). I assume that it was possible to fix it by changing some compiler settings but I wasn’t sure how to do this. Here is a diff that was applied to lib/alpr folder https://gist.github.com/OgrePet/9a15a41f919bcdd7f6353fb62acfb12d

  4. Also there were a few of additional dependencies that were need to be installed. Currently I can hardly remember but in result i had following packages installed by home-brew (all were installed during openalpr compilation)

autoconf cmake fribidi graphite2 libffi pango pkg-config automake fontconfig gettext harfbuzz libpng pcre cairo freetype glib icu4c libtool pixman

snamrata007 commented 6 years ago

Where does it need to replace configs? #Step 3 #30 (comment)