Postgresql gem install pg 0.18.4 passes, bundle install fails - ruby-on-rails

Mac OS El Capitan
Bundle install fails with:
compiling pg_connection.c
pg_connection.c:2394:3: warning: implicit declaration of function 'gettimeofday' is invalid in C99 [-Wimplicit-function-declaration]
gettimeofday(&currtime, NULL);
^
1 warning generated.
compiling pg_copy_coder.c
compiling pg_errors.c
compiling pg_result.c
compiling pg_text_decoder.c
compiling pg_text_encoder.c
compiling pg_type_map.c
compiling pg_type_map_all_strings.c
compiling pg_type_map_by_class.c
compiling pg_type_map_by_column.c
compiling pg_type_map_by_mri_type.c
compiling pg_type_map_by_oid.c
compiling pg_type_map_in_ruby.c
compiling util.c
linking shared-object pg_ext.bundle
ld: file not found: dynamic_lookup
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pg_ext.bundle] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/jmintz/Documents/LaunchAngels/radar/vendor/bundle/gems/pg-0.18.4 for inspection.
Results logged to /Users/jmintz/Documents/LaunchAngels/radar/vendor/bundle/extensions/x86_64-darwin-15/2.2.0-static/pg-0.18.4/gem_make.out
...
...
An error occurred while installing pg (0.18.4), and Bundler cannot continue.
Make sure that `gem install pg -v '0.18.4'` succeeds before bundling.
Running 'gem install pg -v '0.18.4' results in:
Building native extensions. This could take a while...
Successfully installed pg-0.18.4
Parsing documentation for pg-0.18.4
Done installing documentation for pg after 4 seconds
1 gem installed
Yet running 'bundle install' again fails. Any suggestions? I've tried uninstalling and reinstalling postgresql with homebrew with no luck

I have got a similar error now on macOS Catalina, but I was not able to successfully run
gem install pg -v '0.18.4'
I found this issue in the puma gem (I know this is another gem) that helped me solve the issue: https://github.com/puma/puma/issues/2304.
There, I found this:
Clang now enables -Werror=implicit-function-declaration by default:
Clang now reports an error when you use a function without an explicit
declaration when building C or Objective-C code for macOS
(-Werror=implicit-function-declaration flag is on). This additional
error detection unifies Clang’s behavior for iOS/tvOS and macOS 64-bit
targets for this diagnostic. (49917738)
And this:
gem install puma:4.3.5 -- --with-cflags="-Wno-error=implicit-function-declaration"
So, I was able to build pg with:
gem install pg -v '0.18.1' -- --with-cflags="-Wno-error=implicit-function-declaration"

The same issue has been faced with all the gems that rely on native extensions such as pg, puma, ffi, etc
I have solved them by passing -- --with-cflags="-Wno-error=implicit-function-declaration"
ex:
gem install pg -v '0.18.4' -- --with-cflags="-Wno-error=implicit-function-declaration"
gem install ffi -v '1.12.2' -- --with-cflags="-Wno-error=implicit-function-declaration"
gem install puma -v '4.3.1' -- --with-cflags="-Wno-error=implicit-function-declaration"

I had to combine Benito's answer and jasonm's answer like below before running bundle (credit to Unixmonkey):
bundle config build.pg '-- --with-cflags="-Wno-error=implicit-function-declaration"'

This isn't an an answer, as such, but it may point you in the right direction... If indeed gem pg has successfully compiled, as you have indicated... Then it maybe that your Ruby project isn't referring to the correct gemset, somehow. As it appears it is attempting to install it again when you bundle install, this should not happen if pg has been compiled and installed in your current gemset. Are you using RVM on your system? Can you also provide more output?

Answer was installing Postgress.app and running
bundle config build.pg --with-pg-config=[Path to pg_config] before bundling

this worked for me on sierra:
gem install pg -v '0.18.3' -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/latest/bin/pg_config

Related

Rails 5: trying to bundle install end getting error with pg gem

I'm using rails 5 and Rubymineand when I try to bundler install I get the following error:
compiling pg_type_map_all_strings.c
compiling pg_type_map_by_class.c
compiling pg_type_map_by_column.c
compiling pg_type_map_by_mri_type.c
compiling pg_type_map_by_oid.c
compiling pg_type_map_in_ruby.c
compiling util.c
linking shared-object pg_ext.bundle
ld: file not found: dynamic_lookup
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pg_ext.bundle] Error 1
make failed, exit code 2
Gem files will remain installed in
/Users/theopap/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/gems/pg-1.0.0 for
inspection.
Results logged to
/Users/theopap/.rbenv/versions/2.4.0/lib/ruby/gems/2.4.0/extensions/x86_6
4-darwin-16/2.4.0-static/pg-1.0.0/gem_make.out
An error occurred while installing pg (1.0.0), and Bundler cannot continue.
Make sure that `gem install pg -v '1.0.0'` succeeds before bundling.
In Gemfile:
pg
I tried uninstalling the pg gem and installing a fresh one according to this answer from #Neeraj Gupta , but still this error appears after bundler install.
Any ideas why this is happening?
You are probably missing the Postgres Development headers/libraries (libpq-dev).
How did you install Postgres?
If you are on MacOS, you can install Postgres via Homebrew and it will include the necessary development headers for you:
brew install postgresql

Could not bundle install because of 'pg'

I'm learning R o R. Then, I want to make a website by using postgresql.
But, this error makes me crazy.
Please, help me !
$ sudo bundle install
creating Makefile
make "DESTDIR="
compiling gvl_wrappers.c
compiling pg.c
compiling pg_connection.c
pg_connection.c:2323:3: warning: implicit declaration of function 'gettimeofday' is invalid in C99 [-Wimplicit-function-declaration]
gettimeofday(&currtime, NULL);
^
1 warning generated.
compiling pg_errors.c
compiling pg_result.c
linking shared-object pg_ext.bundle
ld: file not found: dynamic_lookup
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pg_ext.bundle] Error 1
Gem files will remain installed in /Users/Sean/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pg-0.17.1 for inspection.
Results logged to /Users/Sean/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/pg-0.17.1/ext/gem_make.out
An error occurred while installing pg (0.17.1), and Bundler cannot continue.
Make sure that `gem install pg -v '0.17.1'` succeeds before bundling.
I tried all ways I could.
For example, I tried to change pass of pg.
But, I couldn't.
Then, I tried
$ brew update
$ brew uninstall postgresql
$ brew install postgresql
$ gem install pg
$ bundle install
But, it didn't work.
How can I do for this error !?
You might require libpq-dev, which is the library that always gets me when trying to install the pg gem on a new machine.
I struck the same problem when running the pg gem 0.17 with Ruby 2.2.1
I just did a bundle update pg and it upgraded to 0.18 and it no longer had this compile issue

event machine gem bundle install is not working

I am following a tutorial and had to do a bundle install following the forking & cloning of a repository. Subsequently we are instructed to run bundle install. However, it is not working and I am getting the following error message:
make
generating rubyeventmachine-i386-mingw32.def
compiling binder.cpp
In file included from binder.cpp:20:0:
project.h:85:0: warning: "FD_SETSIZE" redefined
<command-line>:0:0: note: this is the location of the previous definition
compiling cmain.cpp
In file included from cmain.cpp:20:0:
project.h:85:0: warning: "FD_SETSIZE" redefined
<command-line>:0:0: note: this is the location of the previous definition
cmain.cpp: In function 'int evma_send_file_data_to_connection(long unsigned int,
const char*)':
cmain.cpp:752:6: error: 'fstati64' was not declared in this scope
make: *** [cmain.o] Error 1
Gem files will remain installed in c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0
.0/gems/eventmachine-0.12.10 for inspection.
Results logged to c:/RailsInstaller/Ruby2.0.0/lib/ruby/gems/2.0.0/gems/eventmach
ine-0.12.10/ext/gem_make.out
An error occurred while installing eventmachine (0.12.10), and Bundler cannot
continue.
Make sure that `gem install eventmachine -v '0.12.10'` succeeds before bundling.
I'm rather stuck on what to do at this point. I am on a Windows machine, any advice on how to troubleshoot this?
Try gem install eventmachine -v '0.12.10' Or sudo gem install eventmachine -v '0.12.10' and then retry bundle install.
Some gem needs sudo privileges to install.
For windows gem install eventmachine --pre. Its a known issue for window with ruby 1.9. https://github.com/eventmachine/eventmachine/issues/319
I was able to fix this by installing the latest version of the Eventmachine gem: https://rubygems.org/gems/eventmachine
And then subsequently instaling the latest version of the SQLite gem:
http://rubygems.org/gems/sqlite3-ruby
You might be prompted to update your Gemlockfile make sure to do that then everything else should work.

Cannot install Puma gem on Ruby on Rails

I'm trying to install the puma gem, but when I run
gem install puma
I get this error message:
Temporarily enhancing PATH to include DevKit
Building native extensions. This could take a while...
ERROR: Error installing puma:
ERROR: Failed to build gem native extension.
C:/Ruby193/bin/ruby.exe extconf.rb
creating Makefile
make
generating puma_http11-i386-mingw32.def
compiling http11_parser.c
ext/http11/http11_parser.rl: In function 'puma_parser_execute':
ext/http11/http11_parser.rl:111:3: warning: comparison between signed and unsigned integer expressions
compiling io_buffer.c
io_buffer.c: In function 'buf_to_str':
io_buffer.c:119:3: warning: pointer targets in passing argument 1 of 'rb_str_new' differ in signedness
c:/Ruby193/include/ruby-1.9.1/ruby/intern.h:653:7: note: expected 'const char *' but argument is of type 'uint8_t *'
compiling mini_ssl.c
In file included from mini_ssl.c:3:0:
c:/Ruby193/include/ruby-1.9.1/ruby/backward/rubyio.h:2:2: warning: #warning use "ruby/io.h" instead of "rubyio.h"
mini_ssl.c:4:25: fatal error: openssl/bio.h: No such file or directory
compilation terminated.
make: *** [mini_ssl.o] Error 1
Gem files will remain installed in C:/Ruby193/lib/ruby/gems/1.9.1/gems/puma-2.6.0 for inspection.
Results logged to C:/Ruby193/lib/ruby/gems/1.9.1/gems/puma-2.6.0/ext/puma_http11/gem_make.out
Adding gem 'puma' to my Gemfile and running bundle install isn't an option, because that just doesn't work with any gem and gives me an error message (which is a separate issue, one that I've circumvented with the other gems I've used by installing them via gem install).
Came across very same issue.
sudo apt-get install libssl-dev
fixed it for me.
I ran bundle update before bundle install and that solved the issue for me.
I'm not sure if that was the only thing that helped, as I manually updated puma before that, using these steps:
Checked which version of openssl Ruby is using by running ruby -v -ropenssl -e "puts OpenSSL::OPENSSL_VERSION"
Downloaded the right openssl version from
http://packages.openknapsack.org/openssl/openssl-1.0.0o-x86-windows.tar.lzma
(got the link from https://github.com/hicknhack-software/rails-disco/wiki/Installing-puma-on-windows and edited it based on the output of #1).
Extracted openssl using http://www.7-zip.org to C:\RailsInstaller\openssl
gem install puma -- --with-opt-dir=C:/RailsInstaller/openssl
Figured out the solution to the puma bundle. Followed directions from https://github.com/hicknhack-software/rails-disco/wiki/Installing-puma-on-windows
First you need to download:
DevKit compatible with your ruby version
OpenSSL Developer Package (contains header files and binaries)
And then:
Install DevKit, e.g. in c:\devkit
Unpack the OpenSSL Package, e.g. in c:\openssl (use 7Zip or PeaZip)
You need to copy the ddls from the bin directory (libeay32.dll and ssleay32.dll) to your ruby/bin directory.
Open a windows console
Initialize the DevKit build environment: c:\devkit\devkitvars.bat (except here, I used this in command prompt instead: ruby dk.rb init)
Now it’s possible to install the puma gem with the OpenSSL packages:
gem install puma -- --with-opt-dir=c:\openssl
I think you hit issue #430
https://github.com/puma/puma/issues/430
Re-installing Ruby might help you as well as it closed this issue on GitHub.

bundle install / update: libv8 (therubyracer) installation fails (with native extensions)

I recently wanted to update my gem bundle but ran into installation problems with libv8 (requirement for therubyracer):
Installing libv8 (3.3.10.3) with native extensions /usr/local/rvm/rubies/ruby-1.9.3-head/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:552:in `rescue in block in build_extensions': ERROR: Failed
to build gem native extension. (Gem::Installer::ExtensionBuildError)
/usr/local/rvm/rubies/ruby-1.9.3-head/bin/ruby extconf.rb
Checking for Python...*** 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.
I have found the issue report on therubyracer github site and it suggests to uninstall and reinstall libv8, but this does not work on my Ubuntu 11.04 machine. Any ideas - or am I stuck with the old version for a while?
Try that one for a little while:
gem 'therubyracer'
gem 'libv8', '3.16.14.3'
Should help.
Also it's better with a new bundler: gem install bundler --pre
I had a similar issue on my good old Ubuntu 10.04 (x64)
After I updated the project Gemfile had those gems
gem 'libv8', '~> 3.11.8'
gem "therubyracer", '>= 0.11.0beta1', :require => 'v8'
But when I ran 'bundle install' I got an error
Installing therubyracer (0.11.0beta1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/home/sseletskyy/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for main() in -lpthread... yes
creating Makefile
make
compiling array.cc
compiling script.cc
compiling object.cc
compiling constants.cc
compiling signature.cc
compiling value.cc
compiling locker.cc
compiling init.cc
compiling heap.cc
compiling date.cc
compiling message.cc
compiling accessor.cc
compiling context.cc
compiling exception.cc
compiling backref.cc
compiling trycatch.cc
compiling gc.cc
compiling handles.cc
compiling stack.cc
compiling template.cc
compiling function.cc
compiling primitive.cc
compiling rr.cc
compiling v8.cc
compiling invocation.cc
compiling string.cc
compiling external.cc
compiling constraints.cc
linking shared-object v8/init.so
/home/sseletskyy/.rvm/gems/ruby-1.9.3-p194/gems/libv8-3.11.8.2-x86_64-linux/vendor/v8/out/x64.release/obj.target/tools/gyp/libv8_base.a: could not read symbols: No such file or directory
collect2: ld returned 1 exit status
make: *** [init.so] Error 1
Gem files will remain installed in /home/sseletskyy/.rvm/gems/ruby-1.9.3-p194/gems/therubyracer-0.11.0beta1 for inspection.
Results logged to /home/sseletskyy/.rvm/gems/ruby-1.9.3-p194/gems/therubyracer-0.11.0beta1/ext/v8/gem_make.out
An error occured while installing therubyracer (0.11.0beta1), and Bundler cannot continue.
Make sure that `gem install therubyracer -v '0.11.0beta1'` succeeds before bundling.
Here's a list of steps which worked for me to solve that block quickly
Uninstall all versions of gems 'libv8' and 'therubyracer'
> gem uninstall therubyracer
> gem uninstall libv8
Install therubyracer manually
> gem install therubyracer
Fetching: libv8-3.3.10.4-x86_64-linux.gem (100%)
Fetching: therubyracer-0.10.1.gem (100%)
Building native extensions. This could take a while...
Successfully installed libv8-3.3.10.4-x86_64-linux
Successfully installed therubyracer-0.10.1
2 gems installed
Installing ri documentation for libv8-3.3.10.4-x86_64-linux...
Installing ri documentation for therubyracer-0.10.1...
Installing RDoc documentation for libv8-3.3.10.4-x86_64-linux...
Installing RDoc documentation for therubyracer-0.10.1...
Check versions of installed gems
> gem list | grep libv
libv8 (3.3.10.4 x86_64-linux)
> gem list | grep therubyracer
therubyracer (0.10.1)
Set those versions in Gemfile and run
> bundle install
Summary. Well I understand that in my case I used not the latest versions and it could be bad for compatibility sake. But at least I could continue development.
Ubuntu 11.04
gem "therubyracer", '0.11.1'
gem 'libv8'
Uninstall therubyracer and libv8 gem
Update the bundler gem version
Install lib8-dev package
sudo apt-get install libv8-dev
Then run this
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion imagemagick graphicsmagick libmagickcore-dev libmagickwand-dev
Now install therubyracer manually
gem install therubyracer
It will install therubyracer and libv8 for you.
Now run bundle install
All above steps solved my problem :)
I've run into the same issue recently. Here is a bit of helpful information from the RoR.org 'Getting Started with Rails' Guide:
Compiling CoffeeScript to JavaScript requires a JavaScript runtime and the absence of a runtime will give you an execjs error. Usually Mac OS X and Windows come with a JavaScript runtime installed. Rails adds the therubyracer gem to Gemfile in a commented line for new apps and you can uncomment if you need it. therubyrhino is the recommended runtime for JRuby users and is added by default to Gemfile in apps generated under JRuby. You can investigate about all the supported runtimes at ExecJS.
Based on what I've read elsewhere it seems that Windows support for the therubyracer gem is not there in the '3.3.10.4' version (possibly there in a more recent version, didn't read in that far though). I've installed python 2.7 and got it to compile but you still get errors later during the environment setup process.
So it comes down to this. Check out therubyracer documentation here. 'therubyracer' provides these features (:
Evaluate Javascript from with in Ruby
Embed your Ruby objects into the Javascript world
Manipulate JavaScript objects and call JavaScript functions from Ruby
API compatible with the The Ruby Rhino (for JRuby: http://github.com/cowboyd/therubyrhino)
If you ABSOLUTELY REQUIRE those features then you should switch to *nix and drop Windows for a development/production environment. Otherwise you can do what I did and choose not to install 'therubyracer' or 'libv8' (removed from my Gemfile). I don't rely heavily on JavaScript with the site I'm experiencing this problem with, so I just ignored both gems and all seems well (so far).
Hope this helps someone else in need!
Ubuntu 12.04
gem 'libv8', '3.11.8.3'
gem 'therubyracer', '0.11.0beta5'
Specifying the versions above solved my problem with therubyracer.
Also as someone above suggested, I used the latest bundler:
gem install bundler --pre
Be sure to reference ruby in your Gemfile
gem 'therubyracer', :platform => :ruby
and then run bundle update.
Using these terminal commands fixed it for me on Ubuntu 16.04
sudo apt-get install g++
sudo apt-get install build-essential

Resources