Ruby PDFLib on OSX: LoadError in require - ruby

I just downloaded and installed the Ruby for OSX version of PDFLib (from pdflib.com).
I am using the following setup:
ruby 1.9.3p429 (2013-05-15 revision 40747) [x86_64-darwin12.4.0]
OSX Yosemite 10.10.4
PDFLib 9.0.5
The require 'PDFLib' statement in my Ruby file produces the following error message:
/Users/[...]/.rvm/rubies/ruby-1.9.3-p429/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in 'require': dlsym(0x7ff6e3ef4b90, Init_PDFLib): symbol not found - [...]/PDFLib.bundle (LoadError)
So it seems that the Ruby interpreter cannot find the Init_PDFLib in the library. But from the output of nm I gather that this symbol seems to be present:
$ nm -g ./PDFlib.bundle | grep -i init
0000000000001200 T _Init_PDFlib
[...]
Has anyone any idea what goes wrong? Thanks in advance for your answers.

Found it!
The PDFlib file is called PDFlib.bundle (small l), and my code did a require 'PDFLib' (capitalized L).
It turns out that the require does load the bundle file regardless of the wrong capitalization, but then searches for the Init_PDFLib symbol, which is not present.
So changing the require statement to require 'PDFlib' (small l) worked.

Related

Ruby on Rail running apache show index of when accessing the site

I have recently updated to Apache 2.4, and I am using Ruby on Rail to run my application. Following the upgrade, the site shows a content as seen in the image below, and the error on the log file shows this error message. I have tried using the 'Bundle Install' and checked the permission but that hasn't helped. Any advice would be greatly appreciated. Thanks
[ 2022-02-07 07:47:24.5559 8104/7efc89c8f700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /home/adminuser/hroot: An error occured while starting up the preloader.
Error ID: ba7e6074
Error details saved to: /tmp/passenger-error-RA01E9.html
Message from application: libmysqlclient.so.18: cannot open shared object file: No such file or directory - /usr/local/rvm/gems/ruby-2.0.0-p353#hroot/gems/mysql2-0.3.14/lib/mysql2/mysql2.so (LoadError)
PassengerRuby /usr/local/rvm/gems/ruby-2.0.0-p353#hroot/wrappers/ruby
SetEnv GEM_HOME /root/.gem/ruby/1.9.1
This error shows a problem with the shared objects. You probably updated MySQL/MariaDB libraries with Apache and new libraries are incompatible with your mysql2 gem build. The solution is simple:
First, ensure you are using the ruby-2.0.0-p353#hroot RVM environment.
Then, execute the following command:
gem install mysql2 --version 0.3.14
This should rebuild your mysql2 gem for the new MySQL/MariaDB client libraries on your system.
this isn't the answer anyway but another method to run ruby (in my case Windows 10 ; if you use another OS try to find out how to modify inside index.php the ruby starter)
i post here an alternative method to use apache + php +... and ruby
https://stackoverflow.com/a/71733656/5781320

Windows gem install error: extconf.rb:301:in `assert_has_dev_libs!': invalid byte sequence in UTF-8 (ArgumentError)

I am new to ruby and wanted to add responsive images to my site. I decided to use jekyll-responsive-image. When the install gave me issues, I installed ImageMagick, thinking it was a dependency, following this. Then tried to install rmagick (assuming it is also a dependency) using both
gem install rmagick -v '4.1.2' --source 'https://rubygems.org/'
and
gem install rmagick --platform=ruby -- --with-opt-lib='C:/ImageMagick-7.0.10-Q16-HDRI/lib' --with-opt-include='C:/ImageMagick-7.0.10-Q16-HDRI/include'
The output of these are
checking for Ruby version >= 2.3.0... yes
checking for magick... yes
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include=${opt-dir}/include
--with-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=C:/Ruby27-x64/bin/$(RUBY_BASE_NAME)
extconf.rb:301:in `assert_has_dev_libs!': invalid byte sequence in UTF-8 (ArgumentError)
from extconf.rb:267:in `assert_can_compile!'
from extconf.rb:18:in `initialize'
from extconf.rb:395:in `new'
from extconf.rb:395:in `<main>'
To see why this extension failed to compile, please check the mkmf.log which can be found here:
C:/Ruby27-x64/lib/ruby/gems/2.7.0/extensions/x64-mingw32/2.7.0/rmagick-4.1.2/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in C:/Ruby27-x64/lib/ruby/gems/2.7.0/gems/rmagick-4.1.2 for inspection.
The log does not look helpful
assert_minimum_ruby_version!: checking for Ruby version >= 2.3.0... -------------------- yes
--------------------
find_executable: checking for magick... -------------------- yes
--------------------
It looks like the invalid byte sequence error is stopping me from installing any new gems. Based on other questions on stack overflow, I've tried to check that my path does not contain any specially characters. From this post, I set the user environment variables of LANG, LANGUAGE, and LC_ALL to en_US.UTF-8, and LC_CTYPE to C.BINARY. RUBYOPT is set to -Eutf-8.
How can I solve this error? Keep in mind I'm on Windows 10. Thank you
I just ran into this.
When installing rmagick, the extconf.rb file is running the magick command at the command prompt and running a regex on the output to check the version number. You can reproduce this issue easily by making a simple ruby file with the following content (copied from extconf.rb):
`magick --version` =~ /Version: ImageMagick (\d+\.\d+\.\d+)-+\d+ /
Run this file, and you'll see the same invalid byte sequence exception. We can verify this like so:
str = `magick --version`
str.valid_encoding? # false
From inspecting the output of that magick command on the command prompt, it looks like the version output uses the © symbol (\xA9), which appears to be throwing the exception.
I had an old imagemagick installer lying around (~2 months old) which used a simple C instead of © in the copyright output, and that version of imagemagick seems to allow rmagick to install properly. You may want to dig around for an older installer and see if this resolves your issue.

Issues installing libxml gem for ruby on windows

There are a few threads on questions similar to this, but none have proven effective. I attempted asking on the github page with no luck either.
When I attempt the standard command:
gem install libxml-ruby
I receive an error where the installer cannot find libxml2.dll. I found a stackoverflow thread with a similar issue and followed a user's guidelines here on where to grab the missing libraries and where to include them.
If I add arguments to the install command to point at the directories with the missing libraries using the following:
gem install libxml-ruby -- with-xml2-include=C:\Ruby200\include\libxml2 --with-iconv-include=C:\Ruby200\include
I now get an error where the installer can’t find a “iconv.h” header which is in my C:\Ruby200\include directory.
C:\Users\gonz102>gem install libxml-ruby -- with-xml2-include=C:/Ruby200/include
/libxml2 --with-iconv-include=C:/Ruby200/include
Temporarily enhancing PATH to include DevKit...
Building native extensions with: 'with-xml2-include=C:/Ruby200/include/libxml2 -
-with-iconv-include=C:/Ruby200/include'
This could take a while...
ERROR: Error installing libxml-ruby:
ERROR: Failed to build gem native extension.
C:/Ruby200/bin/ruby.exe extconf.rb with-xml2-include=C:/Ruby200/include/libx
ml2 --with-iconv-include=C:/Ruby200/include
checking for libxml/xmlversion.h in /opt/include/libxml2,/opt/local/include/libx
ml2,/usr/local/include/libxml2,/usr/include/libxml2... yes
checking for xmlParseDoc() in -lxml2... yes
checking for rb_io_bufwrite() in ruby/io.h... yes
creating extconf.h
creating Makefile
make "DESTDIR="
compiling libxml.c
In file included from C:/Ruby200/include/libxml2/libxml/parser.h:810:0,
from ruby_libxml.h:7,
from libxml.c:1:
C:/Ruby200/include/libxml2/libxml/encoding.h:28:19: fatal error: iconv.h: No suc
h file or directory
compilation terminated.
make: *** [libxml.o] Error 1
Gem files will remain installed in C:/Ruby200/lib/ruby/gems/2.0.0/gems/libxml-ru
by-2.9.0 for inspection.
Results logged to C:/Ruby200/lib/ruby/gems/2.0.0/gems/libxml-ruby-2.9.0/ext/libx
ml/gem_make.out
If anyone has any suggestions on what to investigate next or possible solutions I'd greatly appreciate it. I've been stumped on this for over a long while, coming back to it whenever I run into a project with libxml and would gladly take any advice.
Many thanks.
I was unsuccessful with installing libxml version 2.9.0 but 2.7.0 worked just fine. I should specify I'm running windows 7 and Ruby 2.0 32 bit. Here is what I had to do:
-I followed Wik's response here, grabbing all the missing libraries from them mingw64. Admittedly, I'm not sure if I needed all of them, but I sort of took a shotgun approach here.
Added the following to my system path:
Ruby200\lib\ruby\gems\2.0.0\gems\libxml-ruby-2.7.0-x86-mingw32\lib\libs
Executed the following in command line:
gem install libxml-ruby -v2.7.0 -- with-xml2-include:=C/Ruby200/include/libxml2 --with-iconv-include:=C:/Ruby200/include
After that, I the gem, at long last, installed and was actually usable.

ruby, rails gem install error - ERROR: While executing gem ... (Encoding::UndefinedConversionError)

I tried with last version with ruby, but when run gem install rails, always got an error
ERROR: While executing gem ... (Encoding::UndefinedConversionError)
U+041D to IBM437 in conversion from UTF-16LE to UTF-8 to IBM437
I am using windows 8.
but gem list ---local working.. only on install, my locale set english.
what kind problem is it?
Use this link:
https://bugs.ruby-lang.org/issues/10300
They said that you need to chance the enconding at The registry.rb file:
Folder: Ruby2.1.0\lib\ruby\2.1.0\win32
File: registry.rb
Line: 70
- LOCALE = Encoding.find(Encoding.locale_charmap)
+ LOCALE = Encoding::UTF_8
+ #LOCALE = Encoding.find(Encoding.locale_charmap)
We'll need more information to solve your problem. What command are you running?
The meaning of the exception is that some character in the gem is invalid in ibm437, a common 'extended ascii' encoding on Windows machines.
You may be to work around the problem by setting your internal encoding to UTF-8. Encoding.default_internal = Encoding::UTF_8
Would you mind adding the output a running a ruby file containing just the following:
p [Encoding.default_external, Encoding.default_internal, __ENCODING__, Encoding.find('filesystem'), Encoding.find('locale')]
Thanks. If you only do it in irb that's fine to.

How do I determine if my R installation on OS X has the "--enable-R-shlib" option enabled?

I've installed R on my OS X machine via the .pkg method. I'm trying to get a Ruby gem called RSRuby to work and though it installed correctly, it's throwing an error when I try to invoke the gem.
Fatal error: R home directory is not defined
The RSRuby documentation states that R should be installed with the option --enable-R-shlib. But the R documentation states that the Mac OS X installation does this by default. How can you verify that this option is enabled on an installation if you don't know it was explicitly called during installation?
I'm chasing down why RSRuby can't find R home directory and this seems like the most likely problem.
Per RSRuby documentation, I copied this into my home directory
[~]$ R_HOME=/Library/Frameworks/R.framework/Resource
And from the R console, this is the output:
> R.home()
[1] "/Library/Frameworks/R.framework/Resources"
And during gem install, I ran this command:
gem install rsruby -- --with-R-dir=$R_HOME=/Library/Frameworks/R.framework/Resources
Also, these are the contents of my /Library/Frameworks/R.framework/Libraries folder:
[Libraries]$ ls
i386 libRblas.dylib.dSYM libgfortran.2.dylib
libR.dylib libRblas.vecLib.dylib libreadline.5.2.dylib
libR.dylib.dSYM libRlapack.dylib libreadline.dylib
libRblas.0.dylib libRlapack.dylib.dSYM ppc
libRblas.dylib libgcc_s.1.dylib x86_64
Briefly:
You can check for --enable-R-shlib by looking at thethe binary of the resulting R built; on Linux I can do ldd /usr/lib/R/bin/exec/R which reveals that libR.so --- the shared R library --- is loaded by this binary. That is what other projects embedding R (RInside, littler, the R-in-Apache modules, ...) use and presumably what RSRuby would use.
If you get an error 'R home directory not defined' I would start by defining the environment variable R_HOME.
Edit: Regaring Question 1, on OS X, your dynamic libraries end in .dylib. So the directory listing you show clearly demonstrates that R was built with --enable-R-shlib as a compile-time option. Regarding Question 2, the very first Google hit I got for rsruby os x clearly describes how to set R_HOME on OS X (as I had told you), see https://github.com/alexgutteridge/rsruby.

Resources