Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Q:Heroku Zbar Didn't find libzbar on your system (LoadError) #8

Closed
yoshidaagri opened this issue Jun 27, 2014 · 23 comments
Closed

Q:Heroku Zbar Didn't find libzbar on your system (LoadError) #8

yoshidaagri opened this issue Jun 27, 2014 · 23 comments

Comments

@yoshidaagri
Copy link

I have a rails application which uses zbar. It works fine on my developer machine But when i tried to deploy it to Heroku my commit was rejected with the following message:

app/web.1: /app/vendor/bundle/ruby/2.0.0/gems/zbar-0.2.2/lib/zbar/lib.rb:12:in rescue in <module:ZBar>': Didn't find libzbar on your system (LoadError) app/web.1: Please install zbar (http://zbar.sourceforge.net/) or set ZBAR_LIB if it's in a weird place app/web.1: FFI::Library::ffi_lib() failed with error: library names list must not be empty app/web.1: from /app/vendor/bundle/ruby/2.0.0/gems/zbar-0.2.2/lib/zbar/lib.rb:9:inmodule:ZBar'

Here is my gemfile;
gem 'zbar', '~> 0.2.2'

my /.buildpacks:
https://github.com/ballantyne/heroku-buildpack-zbar
https://github.com/heroku/heroku-buildpack-ruby.git

Why does this happen?
Thanks.

@willglynn
Copy link
Owner

It looks like that buildpack is putting libzbar.so in /app/vendor/lib. I'd say that qualifies as a weird place, and the zbar gem doesn't look for it there, so it doesn't find it. Try setting the ZBAR_LIB environment variable (i.e. config variable) directly:

$ heroku config:set ZBAR_LIB=/app/vendor/lib/libzbar.so

If it's not there, try heroku run bash to poke around inside the slug and find its precise location and filename.

@yoshidaagri
Copy link
Author

thanks for the help! deploy completed.

but method from_jpeg fails with "JPEG datastream contains no image
Your libzbar has a JPEG bug. Some images will fail to process correctly.
See: https://github.com/willglynn/ruby-zbar/blob/master/lib/zbar/jpeg.rb ".

my application controller.create:
@upload_file = params[:app][:image];
@barcode = ZBar::Image.from_jpeg(@upload_file.read).process;

What should I do?
Old libzbar in the buildpack?

@willglynn
Copy link
Owner

What should I do?
Old libzbar in the buildpack?

It's not so much old as it is unpatched. The current release version (zbar-0.10) has a bug that makes it break when handling various JPEGs. The zbar gem has a runtime check for this bug and warns you when it detects failure. Applying the patch at https://gist.github.com/willglynn/5659946 fixes it.

I think the right way to do this would be to fork the buildpack, add the patch file, apply it hereabouts, and open a pull request with the buildpack maintainer to get it merged upstream.

@andyweiss1982
Copy link

Hi there, I am having the same problem but the fix outlined in this thread did not work for me. I tried heroku run bash and navigated into vendor but there is no lib folder.
screen shot 2015-08-03 at 3 40 59 pm

Any advice as to how I can find the correct path? The library is working just fine on my local machine.

@andyweiss1982
Copy link

Updates on this end -- I am now using the following buildpacks:

https://github.com/generalui/heroku-buildpack-zbar
https://github.com/heroku/heroku-buildpack-ruby

I can see in the compilation that zbar is being installed.
screen shot 2015-08-03 at 4 26 03 pm

and in heroku run bash I see a zbar folder
screen shot 2015-08-03 at 4 27 48 pm

but I don't see a libzbar.so file and the deploy is still failing:

screen shot 2015-08-03 at 4 26 31 pm

Is there a better buildpack that you recommend? I see many "yet to be official" heroku zbar buildpacks on github but haven't had success with any.

Thanks for your work on this library!

@willglynn
Copy link
Owner

I have limited connectivity at the moment, but try something like:

$ heroku run bash
…
~ $ find / -name '*zbar*.so*`

Hopefully there's a libzbar.so somewhere in your slug. (It looks like the linked buildpack does a make install, so maybe it's in /usr/local/lib?) Assuming you find one, inform the zbar gem using an environment variable:

$ heroku config:set ZBAR_LIB=/path/to/libzbar.so

Hope that helps!

@andyweiss1982
Copy link

Hi Will, thanks for the advice -- I see a libzbar.rc but no libzbar.so. Should I probably try another buildpack?

@michaelryu
Copy link

Having the same problem, I can't find libzar even with the command. It's not located in the usr/local path either.

@michaelryu
Copy link

So after contacting the zbar-buildpack owner, he recommended using the apt-buildpack instead. It looked like it was going to work because it installed libzbar0 just fine but it didn't create a libzbar.so file so I tried libzbar-dev.

libzbar-dev created a libzbar.so file in /app/.apt/usr/lib/libzbar.so

Unfortunately when I point to it in heroku config
heroku config:set ZBAR_LIB=/app/.apt/usr/lib/libzbar.so, it still displays

LoadError: Didn't find libzbar on your system
remote:        Please install zbar (http://zbar.sourceforge.net/) or set ZBAR_LIB if it's in a weird place
remote:        FFI::Library::ffi_lib() failed with error: library names list must not be empty'

@andyweiss1982
Copy link

@michaelryu, I am posting a stack overflow question about this in case anyone in the community has had any success with it. Please upvote! http://stackoverflow.com/questions/31812168/how-can-i-get-zbar-to-deploy-on-heroku

@andyweiss1982
Copy link

@michaelryu I am now in the same place as you.

I used the apt-buildpack:

`=== testing-aptfile Buildpack URLs

  1. https://github.com/ddollar/heroku-buildpack-apt
  2. https://github.com/heroku/heroku-buildpack-ruby`

And I made an Aptfile, saved it to root, with only the word “libzbar-dez” in it.

I was able to find a libzbar.so file — this is progress for me!

Running bash attached to terminal... up, run.5242 ~ $ find / -name "libzbar.so" /app/.apt/usr/lib/libzbar.so

I set the ENV variable ZBAR_LIB.

ZBAR_LIB: /app/.apt/usr/lib/libzbar.so

But when I push to Heroku, I get the same error message as before:

remote: LoadError: Didn't find libzbar on your system remote: Please install zbar (http://zbar.sourceforge.net/) or set ZBAR_LIB if it's in a weird place remote: FFI::Library::ffi_lib() failed with error: Could not open library '/app/.apt/usr/lib/libzbar.so': /app/.apt/usr/lib/libzbar.so: cannot open shared object file: No such file or directory

@willglynn Do you see anything I might be doing wrong here? Anything you might see would be a huge help.

@willglynn
Copy link
Owner

Hmm:

…
/app/.apt/usr/lib/libzbar.so: cannot open shared object file: No such file or directory

This path appears in find(1) output, but open(2) returns ENOENT? Is it a symlink to a nonexistent path, or something?

Now I'm curious about the output of:

$ heroku run bash
…
~ $ ls -l /app/.apt/usr/lib/libzbar.so
~ $ file /app/.apt/usr/lib/libzbar.so

@andyweiss1982
Copy link

Hi @willglynn, thanks for following up. I'm still stuck!

Here is the ouput of the terminal commands:

$ heroku run bash Running bashattached to terminal... up, run.3002 ~ $ ls -l /app/.apt/usr/lib/libzbar.so lrwxrwxrwx 1 u16314 16314 16 Oct 22 2013 /app/.apt/usr/lib/libzbar.so -> libzbar.so.0.2.0 ~ $ file /app/.apt/usr/lib/libzbar.so /app/.apt/usr/lib/libzbar.so: symbolic link tolibzbar.so.0.2.0'`

@willglynn
Copy link
Owner

Does libzbar.so.0.2.0 exist too? The ENOENT seems to imply that it does not.

@andyweiss1982
Copy link

looks like it does -- good sign?

$ heroku run bash Running bash attached to terminal... up, run.3824 ~ $ find / -name "libzbar.so.0.2.0" /app/.apt/usr/lib/libzbar.so.0.2.0

@andyweiss1982
Copy link

I tried setting ZBAR_LIB to /app/.apt/usr/lib/libzbar.so.0.2.0 but still getting the same error with these two buildpacks:

  1. https://github.com/ddollar/heroku-buildpack-apt
  2. https://github.com/heroku/heroku-buildpack-ruby

remote: LoadError: Didn't find libzbar on your system remote: Please install zbar (http://zbar.sourceforge.net/) or set ZBAR_LIB if it's in a weird place remote: FFI::Library::ffi_lib() failed with error: Could not open library '/app/.apt/usr/lib/libzbar.so.0.2.0': /app/.apt/usr/lib/libzbar.so.0.2.0: cannot open shared object file: No such file or directory

@willglynn
Copy link
Owner

Could you make a test case repo I can clone and deploy to Heroku? I don't understand why it's failing with No such file or directory, but given a Heroku app I can touch, I'll have much better visibility.

@andyweiss1982
Copy link

Sure thing, thanks so much for following me through this. This is a more or less blank repo: https://github.com/andyweiss1982/aptfile-test

All I have added is the Aptfile with the string "libzbar-dev" in it, and placed a barcode.jpg in the public folder. This is the heroku url, but there is an application error related to the deploy issues: https://aptfile-test.herokuapp.com/

If you send me your email address, I can add you as a collaborator on heroku so you can see that side as well. My email is my github username at gmail dot com.

Thanks again!

@willglynn
Copy link
Owner

I started a bash dyno, from which I ran a rails console, showing:

$ heroku run bash --app aptfile-test
…
~ $ bin/rails console
Loading production environment (Rails 4.2.2)
irb(main):001:0> ZBar::JPEG.bugged?
JPEG datastream contains no image
=> true
irb(main):002:0> 

The "JPEG datastream contains no image" messaage is emitted directly to stdout from the bowels of libzbar, and ZBar::JPEG.bugged? makes two different calls to libzbar to distinguish failure modes, so the Ruby gem is definitely communicating with the C shared library as of now.

Checking the Heroku logs, release v9 seems to have been failing:

2015-08-07T17:35:31.979295+00:00 heroku[api]: Deploy b59b15e by andyweiss1982@…
2015-08-07T17:35:31.979295+00:00 heroku[api]: Release v9 created by andyweiss1982@…
2015-08-07T17:35:32.163269+00:00 heroku[slug-compiler]: Slug compilation started
2015-08-07T17:35:32.163352+00:00 heroku[slug-compiler]: Slug compilation finished
2015-08-07T17:35:32.078989+00:00 heroku[web.1]: State changed from crashed to starting
2015-08-07T17:35:35.046174+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 40370 -e production`
2015-08-07T17:35:38.292950+00:00 app[web.1]: /app/vendor/bundle/ruby/2.0.0/gems/zbar-0.2.2/lib/zbar/lib.rb:12:in `rescue in <module:ZBar>': Didn't find libzbar on your system (LoadError)
2015-08-07T17:35:38.292973+00:00 app[web.1]: Please install zbar (http://zbar.sourceforge.net/) or set ZBAR_LIB if it's in a weird place
2015-08-07T17:35:38.292975+00:00 app[web.1]: FFI::Library::ffi_lib() failed with error: Could not open library '/app/.apt/usr/lib/libzbar.so.0.2.0': /app/.apt/usr/lib/libzbar.so.0.2.0: cannot open shared object file: No such file or directory

…while release v10 seems to work:

2015-08-07T17:46:12.432372+00:00 heroku[api]: Deploy 27f93d1 by andyweiss1982@…
2015-08-07T17:46:12.432372+00:00 heroku[api]: Release v10 created by andyweiss1982@…
2015-08-07T17:46:12.481196+00:00 heroku[slug-compiler]: Slug compilation started
2015-08-07T17:46:12.481220+00:00 heroku[slug-compiler]: Slug compilation finished
2015-08-07T17:46:13.024050+00:00 heroku[web.1]: State changed from crashed to starting
2015-08-07T17:46:17.670078+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 26120 -e production`
2015-08-07T17:46:25.868205+00:00 heroku[web.1]: State changed from starting to up
2015-08-07T17:46:25.665639+00:00 app[web.1]: [2015-08-07 17:46:25] INFO  WEBrick 1.3.1
2015-08-07T17:46:25.665774+00:00 app[web.1]: [2015-08-07 17:46:25] INFO  ruby 2.0.0 (2015-04-13) [x86_64-linux]
2015-08-07T17:46:25.666333+00:00 app[web.1]: [2015-08-07 17:46:25] INFO  WEBrick::HTTPServer#start: pid=3 port=26120

https://aptfile-test.herokuapp.com/ currently returns a 404 from the dyno rather than a 503 App Crashed from Heroku's router.

So… it's fixed? What was the issue?

@andyweiss1982
Copy link

This is the strangest thing.

So I went ahead and coded out a barcode scan on the aptfile-test app and pushed it again to heroku, not expecting it to work. Same error on deploy as always:
screen shot 2015-08-08 at 10 30 35 am

But lo and behold, I can visit the site on heroku and the barcode scan is working....
screen shot 2015-08-08 at 10 32 32 am

I have no idea what to make of it. My buildpacks and ENV variables have been the same for the last several deploys.

Any thoughts? I can't make heads or tails of it.

@willglynn
Copy link
Owner

A-ha! The zbar gem is getting loaded in the slug compiler, and in that context the libzbar.so lives at a different path and environment variables work differently.

I'm guessing it's being loaded as part of rake assets:precompile, and I'd also guess it's not needed at all for asset compilation. Try excluding it from the :assets group, or making it require: false and load it only in the code that really does need it.

@andyweiss1982
Copy link

Finally! @michaelryu the require: false in the Gemfile and separately requiring in the controller is what did it for me.

Thank you so much @willglynn for seeing this through to the end.

Answering my own Stack Overflow question here in case anyone has the same problem in the future:
http://stackoverflow.com/questions/31812168/how-can-i-get-zbar-to-deploy-on-heroku

@sheck
Copy link

sheck commented Nov 12, 2015

Hi guys! I was dealing with similar issues the past few weeks and spent a lot of time trying to get it working. I ended up creating a heroku buildpack that uses the patched version of Zbar. I also figured out how to get it running on CircleCI. Maybe it will help someone else in the future!

Heroku:
https://github.com/sheck/heroku-buildpack-zbar

Circle CI:
https://gist.github.com/sheck/475e0c8f2d9f618f1eca

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants