I'm trying to do file uploads with ruby 1.8 and it seems like there are no good out-of-the-box solutions. They all seem to need some 3rd party patch or fork of a project to work. I would use mechanize but I actually need to interface with an xml api and mechanize seems to be made specifically for dealing directly with webpages. I've tried RestClient but it doesn't have that functionality for multipart forms out of the box, you have to use a fork of the project to get it to work. Similar situations seem to exist for Net:HTTP
I'm thinking curb would be the way to go since I may want to use multicurl anyways for some other things I plan to do. However, on my windows machine I can't seem to install the curb gem. gem install curb gives an error saying I need to specify where the curl library lives.. I've tried passing options to extconf but no luck so far.
Here is the output of gem install curb without any options
C:\ruby\lib\ruby\gems\1.8\gems\curb-0.5.4.0>gem install curb
Building native extensions. This could take a while...
ERROR: Error installing curb:
ERROR: Failed to build gem native extension.
C:/ruby/bin/ruby.exe extconf.rb
checking for curl-config... no
checking for main() in curl.lib... no
*** 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
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--srcdir=.
--curdir
--ruby=C:/ruby/bin/ruby
--with-curl-dir
--without-curl-dir
--with-curl-include
--without-curl-include=${curl-dir}/include
--with-curl-lib
--without-curl-lib=${curl-dir}/lib
--with-curllib
--without-curllib
extconf.rb:12: Can't find libcurl or curl/curl.h (RuntimeError)
Try passing --with-curl-dir or --with-curl-lib and --with-curl-include
options to extconf.
Gem files will remain installed in C:/ruby/lib/ruby/gems/1.8/gems/curb-0.5.4.0 for inspection.
Results logged to C:/ruby/lib/ruby/gems/1.8/gems/curb-0.5.4.0/ext/gem_make.out
Any ideas how I can get this to work?
Matt,
I've had trouble installing the curb gem in Windows before. In trying to see how others had solved this I came across a lot of questions and not very many solutions. Having to do it again tonight I decided to document my steps and post the results:
http://beginrescue.blogspot.com/2010/07/installing-curb-with-ruby-191-in.html
Sorry for the blogspam, hope this is useful for somebody.
pete
Ultimately, in win7 with ruby 1.9.1 the following worked for me (where paths need to be updated to reflect the location (and version) of your curl version (which can be obtained via http://curl.haxx.se/download.html#Win32))
gem install curb -- --with-curl-lib="C:/curl/curl-7.21.1-devel-mingw32/bin" --with-curl-include="C:/curl/curl-7.21.1-devel-mingw32/include"
This did take a few minutes to process, so be patient.
I used Evan's install config in his answer with the correct libcurl binary from the wizard: http://curl.haxx.se/dlwiz/
gem install curb -- --with-curl-lib="C:/curl/curl-7.21.1-devel-mingw32/bin" --with-curl-include="C:/curl/curl-7.21.1-devel-mingw32/include"
This worked for me on win XP 64 bit.
Make sure to select libcurl with the description about being the binary for libcurl software development.
Looking at the underlying issue you are trying to solve. I was looking for a multpart-post client before and spent a lot of time trying out diffrent gems/tools.
The only one i found that worked satisfactory was Nick Siegers multipart-post gem
It was very straightforward to use, I highly recommend it.
Here is sample code i made for my test
require "rubygems"
require 'net/http/post/multipart'
url = URI.parse('http://localhost:3000/mytest/1.xml')
File.open("c:/temp/readme.txt") do |jpg|
req = Net::HTTP::Put::Multipart.new url.path,
"mytest[attachment]" => UploadIO.new(jpg, "text/plain", "c:/temp/readme.txt")
res = Net::HTTP.start(url.host, url.port) do |http|
http.request(req)
end
puts res.inspect
end
As I commented already, I did find a solution which was simply using the rest-client provided in the github gems..
gem install rest-client
will get the job done.
From there you can do a multipart post which can contain 1 or more files.. It has all the flexibility one could need in a rest-client.
See the documentation here: http://rdoc.info/projects/archiloque/rest-client
for examples on how to use it.
The only thing I found that it didn't do correctly was parsing cookies. The cookies my company uses can have equal signs in the values and it doesn't parse them correctly. I had put in some hacks to get around the issue but eventually that came back to bite me.. So just the other day I started analyzing the code from Mechanize/WEBrick and was able to utilize the CookieJar from Mechanize to manage cookies from the rest-client.. Hopefully I can get the author of the rest-client to build this functionality into the rest-client so others won't have the same problems I had..
For Windows 8 the command was:
gem install curb -- --with-curl-lib=C:/Utils/curl-7.32.0-dev/lib64 --with-curl-include=C:/Utils/curl-7.32.0-dev/include
And it nearly installs. Now there are "undefined reference" warnings/errors
That works too, on Windows 10 x64:
gem install curb -- --with-curl-lib="C:/Users/WindowsVM/binaries/curl-7.40.0-devel-mingw64/lib64" --with-curl-include="C:/Users/WindowsVM/binaries/curl-7.40.0-devel-mingw64/include"
When you say you passed configuration options to extconf.rb, did you mean in the gem install command?
If not, I believe it would be something along the lines of
gem install curb -- --with-curl-dir=dir
It might be a different config option, but the -- is that bit you need to pass it configure options.
Execute Below command and its works
gem install curb --platform=mswin32
after a lots of time spending on it, I give up...
The answers given above don't work for me, and some of the "curl" links are broken, I can't even download from the official web-site.
what I want is quite simple: install curb gem on cygwin.
Now I switched to VirtalBox, and installed a Ubuntu server on it. then, I install it in 20 minutes without any problems.
So, People working under cygwin, let's switch to Virtual Machine!
I tried all of the solutions above and nothing worked, I gave up but luckily I later stumbled upon this post http://jooglar.com/edely/content/installing-libcurl-ruby-windows and the instructions there worked perfectly.
Here are the directions, in case the website goes belly up:
1. Download the "libcurl" version of the library
From http://curl.haxx.se/dlwiz/?type=lib
2. Install wherever, but the path cannot have spaces.
Be sure that when you unzip the file, you find the directories “bin” and “include”
3. Add the libcurl path (ending in /bin;) to the system PATH variable
WARNING: USE / INSTEAD OF \ in the PATH. No spaces allowed in the path. For example:
C:/curl/curl-7.26.0-devel-mingw32/bin;
4. Install the gem
WARNING: AGAIN, USE / INSTEAD OF \ in the PATH. See above.
Example command: gem install curb -- --with-curl-lib=C:/curl/curl-7.26.0-devel-mingw32/bin --with-curl-include=C:/curl/curl-7.26.0-devel-mingw32/include
[NB: Note the standalone -- before --with-..., this was a gotcha for me.]
At this point, it should work. It worked for me. If it doesn't, you could try the rest of the instructions:
If it does not work, copy the following .dll files to the ruby/bin directory and run again the previous command.
libcurl.dll
libssl32.dll
libeay32.dll
Also, if that does not work...update the DevKit and run again the previous command. Download the latest version and from a console go to the DevKit directory and run
ruby dk.rb install --force
Related
In our Rails application we do require 'RRD' at some point, but that results in a cannot load such file -- RRD. So obviously I used homebrew to install rrdtool, but the error remains.
The docs at https://oss.oetiker.ch/rrdtool/prog/rrdruby.en.html provide two options:
Either:
$: << '/path/to/rrdtool/lib/ruby/1.8/i386-linux'
require "RRD"
In my /opt/homebrew/Cellar/rrdtool/1.8.0/lib directory there's no mention of ruby, which is because of the --disable-ruby-site-install flag in the formula, because when I skip that flag I do actually get something: /opt/homebrew/Cellar/rrdtool/1.8.0/lib/ruby/2.6.0/universal-darwin21. However replacing the path/to string with this path still gives the error.
Or:
If you use the --ruby-site-install configure option you can drop the $: line since the RRDtool module will be found automatically.
Which is a little confusing (and probably outdated) because here it seems that ruby site install is disabled by default and you have to enable it proactively, whereas in the formula it's actually actively disabled.
Either way: both options didn't do the trick for me and if there's a solution without homebrew that's also fine.
For good measure: I'm on macOS Monterey
TL;DR
For the most part, I'd say that using a non-standard gem without a Ruby version manager is your main issue. There are instructions on the rrdruby site for installing it, but they don't follow typical conventions, so your mileage will vary.
Some Practical Suggestions
The require keyword is for gems, not binaries. You need to have an rrdtool-related gem installed, available to your Ruby instance (usually through a Bundler Gemfile or gemspec, or via the RUBYOPTS environment variable or your in-process Ruby $LOAD_PATH), and then require the correct name of the gem in your code. For example, using the older rrd-ffi gem:
# use sudo if you're installing it to the system,
# but I would strongly recommend a ruby version
# manager instead
gem install rrd-ffi
# in your Ruby class/module file
require "rrd"
For the gem you seem to be using, you have to compile the gem first to make it usable, and then ensure it's available in your Ruby $LOAD_PATH (or other gem lookup mechanism) before trying to require it. The error message you're seeing is basically telling you that a gem with that name is not available as called within any of the standard lookup locations.
Again, I'd suggest reading the build documentation for your gem, and then seeing if you can install it as part of a Bundler bundle, RVM gemset, or other non-system approach if you can. Otherwise, follow the directions for the rrdruby tool, which is not available as a standard Rubygems.org gem, in order to make it available before trying to require it.
Beware of Outdated or Non-Standard Gems
Most of the RRD gems I found were quite old; most were 7-8 years old or older, so their compatibility with current Rubies is potentially suspect. The gem-builder you're using is newer, but doesn't seem to be designed as a standard gem, so you need to build it and install it in a suitable lookup path before it can be required. Installing gems as system gems is almost always a bad idea, so I'd strongly recommend building it from source and using a ruby version manager rather than following the rrdtool author's atypical suggestions. YMMV.
I'm currently trying to install a few Ruby Gems that require the fftw3 library to be installed and linked correctly on Windows 10. It's a one-line fix on Linux, so I'm rather annoyed at this point.
fftw3 ~> 0.3
convolver ~> 0.3.1
I have Ruby 2.2.4 (64-bit) installed and the 64-bit Devkit installed as well.
Running gem install fftw3 produces the following:
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing fftw3:
ERROR: Failed to build gem native extension.
current directory: C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/fftw3-0.3/ext
C:/Ruby22-x64/bin/ruby.exe -r ./siteconf20180813-7456-1v4icuv.rb extconf.rb
checking for narray.h... yes
checking for narray_config.h... yes
checking for fftw3.h... yes
checking for main() in -lfftw3... no
*** 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
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=C:/Ruby22-x64/bin/$(RUBY_BASE_NAME)
--with-narray-dir
--without-narray-dir
--with-narray-include
--without-narray-include=${narray-dir}/include
--with-narray-lib
--without-narray-lib=${narray-dir}/lib
--with-fftw3-dir
--without-fftw3-dir
--with-fftw3-include
--without-fftw3-include=${fftw3-dir}/include
--with-fftw3-lib
--without-fftw3-lib=${fftw3-dir}/lib
--with-fftw3lib
--without-fftw3lib
** configure error **
Header fftw3.h or the compiled fftw3 library is not found.
If you have the library installed under /fftw3dir (that is, fftw3.h is
in /fftw3dir/include and the library in /fftw3dir/lib/),
try the following:
% ruby extconf.rb --with-fftw3-dir=/fftw3dir
Alternatively, you can specify the two directory separately
with --with-fftw3-include and --with-fftw3-lib.
To see why this extension failed to compile, please check the mkmf.log which
can be found here:
C:/Ruby22-x64/lib/ruby/gems/2.2.0/extensions/x64-mingw32/2.2.0/fftw3-0.3/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/fftw3-0.3 for inspection.
Results logged to C:/Ruby22-x64/lib/ruby/gems/2.2.0/extensions/x64-mingw32/2.2.0/fftw3-0.3/gem_make.out
There is a lot in here...So far I've been able to get the fftw3.h file to link properly by reading the mkmf.log file and placing the headers in a path that's searched by the gem installation. I've tried using more of the command line options ruby extconf.rb <opts> to generate the makefile (receiving similar errors), I've placed the DLL in the System32 and SysWOW64 folders.
The same error populates with the ruby-termios gem, but instead it's looking for termios.h. Which lead me to believe there may be something wrong with the gems that need the Devkit to install, so I tried reinstalling it with no luck as well.
So I have a few questions:
Why do the Devkit gems search for header files that match the gem to be installed? (e.g. fftw3 looks for fftw3.h, ruby-termios looks for termios.h) Shouldn't these come bundled with the gem?
Is it possible that libfftw3 is missing a main() function? I'm unsure if the install command can find the dll, or if the dll is missing main(). If this is the case, what would be the work-around for that problem? (I don't want to remove the have_library("fftw3") call from the extconf.rb file as this just feels dirty and all around incorrect.)
Does anyone know the work-around for this error?
Sorry for throwing so much at you and hopefully this is clear enough.
Thanks in advance.
EDIT: A couple things to note:
On Windows, you can install the fftw3 library during Cygwin's installation
gem install also has an option to install --with-fftw3-dir="path"
To answer your questions in order:
(This is actually a few questions) Typically yes, naming convention is of course going to convey something meaningful, but it is not required. It is quite possible to for the author to have changed the name of a file. Ruby simply looks for an entry-point that must be defined Init_gem_name. Other than that, as long it conforms to C standards and the extconfig.rb is properly configured to tell the compiler where to find source files, anything goes. Any C extension is going to have at least one header to define the entry point, but depending on what the gem does, there may be headers not included. For example, if writing a gem that uses OpenGL, it is not always necessary to include the gl.h header, because it is already included with Windows, OSX, and Linux systems by default (though often outdated).
This is so highly unlikely that I am just going to say NO.
You don't need a "work-around", you need only follow the directions given to use the gem. Not all gems are self-contained libraries that have no dependencies, especially anything that wraps a library. This particular gem requires that libfft3 be installed on your system already, where it can be found, before you install the gem, otherwise all the functions that it thinks it has by reading a header file are not actually defined anywhere.
These steps are for a 64-bit OS with Ruby 2.2.4 and Devkit on Windows 10.
Run Cygwin setup and select mingw64-x86_64-fftw3 (version 3.3.5) for install
Copy C:\cygwin64\usr\x86_64-w64-mingw32\sys-root\mingw\lib\libfftw3* to
C:\fftw3\lib
Copy C:\cygwin64\usr\x86_64-w64-mingw32\sys-root\mingw\include\fftw3* to
C:\fftw3\include
Copy C:\COSMOS\Vendor\Ruby\lib\ruby\gems\2.2.0\gems\narray-0.6.1.2\src\libnarray.a
to C:\fftw3\lib
Copy both narray.h and narray_config.h from <rubypath>\lib\ruby\gems\2.2.0\gems\narray-0.6.1.2\src to C:\fftw3\include
run gem install fftw3 -- --with-opt-dir=C:\fftw3
Add C:\cygwin64\usr\x86_64-w64-mingw32\sys-root\mingw\bin to PATH
These steps will allow the installation of gems that require the fftw3library. You just need to specify the --with-opt-dir option during gem install
I am trying to contribute to a gem I recently took interest in - Nesta. The developer has done a great job in creating one of the lightest, thinest CMSs you can find and I want to document it. I have read through the code and commented on a few methods to the best of my knowledge.
However, I seek to test this out locally by calling gem server and seeing the changes on my machine before pushing it online.
Things I have tried:
Manual edit.
Documented the file.
Fired up gem server.
Using the gem tool.
Documented the file.
Ran gem rdoc nesta --rdoc
Restarted gem server
All to no avail. Please help.
Thank you.
You can preview generated html pages without installing a modified version of the gem on your machine. Add this to nesta's Rakefile:
require 'rake/rdoctask'
Rake::RDocTask.new('doc') do |i|
i.rdoc_files = FileList['lib/**/*']
end
and type rake doc. Then view generated html/index.html file.
Are you sure you've installed the version that you've modified, not the original version?
If you've installed the modified version, but have forgotten to install the rdoc, see Can you install documentation for existing gems?
I'm setting up a project that uses SASS, which uses FSEvents to keep from polling the disk. It seems that this doesn't play nice with RVM, however. That means that when I run sass --watch I get this warning:
Warning: Unable to load CarbonCore. FSEvents will be unavailable.
I realize that it will still work, but I don't want to be polling my disk constantly. I want to get it working with FSEvents. The best information I could find about this was this thread:
http://groups.google.com/group/compass-users/browse_thread/thread/df7d9d0da9ec1eb1
I reinstalled my RVM Ruby (using 1.9.2) as described by Brandon Mathis and downloaded the linked RubyCocoa. However, I get an error on the first step of installing RubyCocoa:
[rvm 1.9.2] ~/Downloads/RubyCocoa-1.0.0 $ ruby install.rb config --build-universal=yes
install.rb: entering config phase...
create ext/rubycocoa/extconf.rb
create framework/GeneratedConfig.xcconfig
create framework/src/objc/Version.h
create tests/Makefile
---> framework
create /Users/xxx/Downloads/RubyCocoa-1.0.0/framework/src/objc/osx_ruby.h ...
config failed
hook /Users/xxx/Downloads/RubyCocoa-1.0.0/framework/post-config.rb failed:
No such file or directory - /Users/xxx/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/x86_64-darwin10.6.0/ruby.h
try 'ruby install.rb --help' for usage
It looks like the problem stems from this being an older version of RubyCocoa (I notice the missing file has 1.9.1 in the path), but in the Google Groups post, Brandon Mathis says specifically to use the version he links and not the newest one.
Does anyone know how to get this configured, or have a link to a recent, hopefully simpler and clearer guide to getting FSEvents working with RVM?
Versions in question:
RVM 1.2.0
Ruby 1.9.2 patch level 136 (installed via RVM)
Mac OS X 10.6.6
HAML gem 3.0.25 (SASS is part of HAML)
Thanks!
I wrote FSSM, which is what HAML/SASS/Compass use for their filesystem watching backend. While rubycocoa isn't supported in 1.9.x, the latest git version of FSSM has pretty solid support for rb-fsevent. This library currently has other limitations, like only being able to monitor one path (parent directory is a must here), but I'm working on it. ;)
I'd highly suggest installing rb-fsevent, and then FSSM from github: https://github.com/ttilley/fssm
If you have any problems, please don't hesitate to file an issue in the tracker. FSSM is a currently maintained project, and it was originally written to help Chris Eppstein out with providing watch functionality in compass (which was later adopted in sass itself). Ease of use via these libraries is my absolute top priority.
This is kind of a lost battle. You can copy the contents of the include/ruby folder from the Ruby source code to that location /Users/xxx/.rvm/rubies/ruby-1.9.2-p136/lib/ruby/1.9.1/x86_64-darwin10.6.0/ which will let you run the config command, but after that you will get a lot of errors on the setup command and you won't be able to install it all. People say RubyCocoa doesn't work with 1.9.2 and I don't know if anyone managed to make it work.
I tried the FSSM method above, to no avail...
Gemfile now has:
group :development do
gem 'rb-fsevent'
gem 'fssm', :git => 'https://github.com/ttilley/fssm.git'
end
which installs:
fssm (0.2.6.1)
rb-fsevent (0.4.0)
Still getting this tho:
Warning: Unable to load CarbonCore. FSEvents will be unavailable.
Anyone have install steps to make FSSM work nicely?
I am trying to install the curb gem, which is libcurl bindings for Ruby, and of course I need to have "A working (lib)curl installation, with development stuff" installed on my computer. So, I went to the cURL Download Wizard and downloaded this package.
But adding the bin into my PATH does not produce improvement and I still get an error when I try to install the curb gem, such as:
extconf.rb:19: Can't find libcurl or curl/curl.h
(RuntimeError)
Even though, curl is already in the PATH.
EDIT: I also tried raking the gem, as per the instructions. It fails saying "make failed" and throwing a bunch of errors like this:
C:/Ruby/lib/ruby/gems/1.8/gems/curb-0.7.7.1/ext/curb_postfield.c:76:
undefined reference to
`_imp__curl_formadd'
Execute Below command for windows only and its works
gem install curb --platform=mswin32
I realise this is a very old question, but I had this exact problem today and found the instructions on someone else's site. These worked for me so I thought I would share them since people with this issue are most likely to come across StackOverflow first: http://jes.al/2012/10/installing-curb-gem-on-windows-7/
In a nutshell:
Get the 32-bit development version of curl (see my notes below)
Add the curl bin directory to your PATH
Run the following command (replacing the paths to curl as necessary)
gem install curb --platform=ruby -- -- --with-curl-lib="C:/curl-7.27.0-devel-mingw32/bin" --with-curl-include="C:/curl-7.27.0-devel-mingw32/include"
A couple of personal notes:
Even though I am on 64-bit Windows 7, I had to download the 32-bit libcurl version under "Win32 - Generic", identified as "Win32 2000/XP zip".
I got the error c:/Ruby193/lib/ruby/1.9.1/mkmf.rb:246:in 'initialize': Permission denied - mkmftmp1.log (Errno::EACCES) while installing the gem. This rather messed up page here suggested that it might be a problem with my anti-virus, and that just retrying a couple of times might work, and indeed, it did.