Compile postgres ruby gem against libpq.a on 10.6.7 - ruby

I'm trying to install the ruby pg gem using a custom compiled postgres 8.4.7. This works as expected:
sudo env ARCHFLAGS='-arch x86_64' gem install pg -- --with-pg-config=/path/to/my/pg_config
The gem compiles and installs correctly, and when required it loads the right dynamic library.
However, I'd like to statically link the gem for portability on multiple machines. My most reasonable attempt:
sudo env ARCHFLAGS='-arch x86_64' gem install pg -- --with-pg-config=/path/to/my/pg_config --with-ldflags='-static'
fails with this error message:
Building native extensions. This could take a while...
ERROR: Error installing pg:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb --with-pg-config=/[edited]/pgsql-8.4.7/bin/pg_config --with-ldflags=-static
checking for /[edited]/pgsql-8.4.7/bin/pg_config... yes
MacOS X build: fixing architecture flags:
using the value in ARCHFLAGS environment variable ("-arch x86_64").
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for PQconnectdb() in -lpq... no
checking for PQconnectdb() in -llibpq... no
checking for PQconnectdb() in -lms/libpq... no
Can't find the PostgreSQL client library (libpq)
Any suggestion?
Thanks!
Update:
From the mkmf.log file:
conftest.c: In function ‘t’:
conftest.c:5: error: too few arguments to function ‘PQconnectdb’
checked program was:
/* begin */
1: #include
2:
3: /*top*/
4: int main() { return 0; }
5: int t() { PQconnectdb(); return 0; }
/* end */

Solved:
Copy Postgres static libraries to a separate location from the [prefix]/lib dir and pass the new path explicitly when building the gem:
sudo env ARCHFLAGS='-arch x86_64' gem install pg -- --with-pg-config=/path/to/my/pg_config --with-pg-lib=/path/to/static/libs
Details:
The crucial information was a bit up in the mkmf.log file:
"gcc -o conftest -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin10.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/[edited]/pgsql-9.0.3/include -arch x86_64 -g -Os -pipe -fno-common -DENABLE_DTRACE -fno-common -pipe -fno-common conftest.c -L. -L/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib -static -L/[edited]/pgsql-9.0.3/lib -lruby -lpq -lpthread -ldl "
ld: library not found for -lcrt0.o
collect2: ld returned 1 exit status
Passing the '-static' flag to the linker was trying to create a completely statically linked binary, which is not supported under Mac OS X:
Static linking of user binaries on Mac OS X

Related

installing mysql2 gem on redhat

Currently trying to install the mysql2 gem on redhat. This is what I'm getting after running gem install
gem install mysql2 -v 0.3.18 -- --with-mysql-config=/usr/bin/mysql_config
checking for ruby/thread.h... *** 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.
It looks like most people who get a similar error need to install mysql dev/lib packages. The packages are already installed and up to date. The mkmf.log file looks like this:
"gcc -o conftest -I/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/x86_64-linux -I/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/backward
-I/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0 -I. -I/home/zdev/.rbenv/versions/2.2.0/include -D_FILE_OFFSET_BITS=64 -O3 -fno-fast-math -ggdb3
-Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings
-Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat conftest.c -L.
-L/home/zdev/.rbenv/versions/2.2.0/lib -Wl,-R/home/zdev/.rbenv/versions/2.2.0/lib -L/home/zdev/.rbenv/versions/2.2.0/lib -lruby-static -lpthread -lrt
-ldl -lcrypt -lm -lc"
In file included from /home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby.h:33,
from conftest.c:1:
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/ruby.h:107: error: size of array 'ruby_check_sizeof_long' is negative
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/ruby.h:111: error: size of array 'ruby_check_sizeof_voidp' is negative
In file included from /home/zdorman/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby.h:33,
from conftest.c:1:
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/ruby.h: In function 'rb_int2num_inline':
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/ruby.h:1303: warning: comparison is always true due to limited range of data type
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/ruby.h:1303: warning: comparison is always true due to limited range of data type
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/ruby.h: In function 'rb_uint2num_inline':
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/ruby.h:1313: warning: comparison is always true due to limited range of data type
In file included from /home/zdorman/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/intern.h:35,
from /home/zdorman/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/ruby.h:1710,
from /home/zdorman/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby.h:33,
from conftest.c:1:
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/st.h: At top level:
/home/zdev/.rbenv/versions/2.2.0/include/ruby-2.2.0/ruby/st.h:52: error: size of array 'st_check_for_sizeof_st_index_t' is negative
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return 0;
6: }
/* end */
The errors in the log file are produced by sanity checks like this:
typedef char ruby_check_sizeof_long[SIZEOF_LONG == sizeof(long) ? 1 : -1];
What could be the cause of this issue? gcc and mysql are both 64 bit - are there any other binaries/libs that would cause this issue?
For the record, there is a copy of the mysql2 gem already installed on this system. It was installed a couple years ago by the original developer, and is tied to a ruby install in /usr/bin. I'm trying to migrate a project over to using a ruby managed by rbenv. From a clean ruby install made through rbenv, bundle install will work flawlessly on our ubuntu box, but it trips up with the mysql2 gem on this system.

Mac 10.8.4 failed to install any native ruby gem extension

I have updated xcode to 5.1 and install the command line tools from preference->downloads page.
But when I try to install ruby gems (e.g. sqlite3, nokogiri), it gives errors like this:
*** 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.
And then I checked the mkmf.log:
" -o conftest -I/Users/alun/.rvm/rubies/ruby-2.1.2/include/ruby-2.1.0/x86_64-darwin13.0 -I/Users/alun/.rvm/rubies/ruby-2.1.2/include/ruby-2.1.0/ruby/backward -I/Users/alun/.rvm/rubies/ruby-2.1.2/include/ruby-2.1.0 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -I/Users/travis/.sm/pkg/active/include -fPIC -mmacosx-version-min=10.7 -pipe -Wno-error=unused-command-line-argument-hard-error-in-future conftest.c -L. -L/Users/alun/.rvm/rubies/ruby-2.1.2/lib -lxml2 -arch x86_64 -lruby-static -framework CoreFoundation -lpthread -ldl -lobjc "
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5: return 0;
6: }
/* end */
I searched but didn't find similar mkmf.log
It seems the build command doesn't specify gcc or any other things.
Finally I've solved my problem, by reinstall xcode and command line tools, and then reinstall ruby with rvm

Errors Installing the gem wdm in cygwin

I keep getting this error while installing the gem wdm from inside cygwin. Does anybody had the same issue and know now to fix it. Thanks. (I am Trying to install Guard gem)
$ gem install wdm
Building native extensions. This could take a while...
ERROR: Error installing wdm:
ERROR: Failed to build gem native extension.
/usr/bin/ruby.exe extconf.rb
checking for main() in -lkernel32... yes
checking for windows.h... yes
checking for ruby.h... yes
checking for HAVE_RUBY_ENCODING_H... yes
creating Makefile
make
gcc -I. -I/usr/include/ruby-1.9.1/i386-cygwin -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -DHAVE_WINDOWS_H -DHAVE_RUBY_H -DHAVE_CONST_HAVE_RUBY_ENCODING_H -ggdb -O2 -pipe -fno-strict-aliasing -o entry.o -c entry.c
gcc -I. -I/usr/include/ruby-1.9.1/i386-cygwin -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -DHAVE_WINDOWS_H -DHAVE_RUBY_H -DHAVE_CONST_HAVE_RUBY_ENCODING_H -ggdb -O2 -pipe -fno-strict-aliasing -o memory.o -c memory.c
gcc -I. -I/usr/include/ruby-1.9.1/i386-cygwin -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -DHAVE_WINDOWS_H -DHAVE_RUBY_H -DHAVE_CONST_HAVE_RUBY_ENCODING_H -ggdb -O2 -pipe -fno-strict-aliasing -o monitor.o -c monitor.c
gcc -I. -I/usr/include/ruby-1.9.1/i386-cygwin -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -DHAVE_WINDOWS_H -DHAVE_RUBY_H -DHAVE_CONST_HAVE_RUBY_ENCODING_H -ggdb -O2 -pipe -fno-strict-aliasing -o queue.o -c queue.c
gcc -I. -I/usr/include/ruby-1.9.1/i386-cygwin -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -DHAVE_WINDOWS_H -DHAVE_RUBY_H -DHAVE_CONST_HAVE_RUBY_ENCODING_H -ggdb -O2 -pipe -fno-strict-aliasing -o rb_change.o -c rb_change.c
rb_change.c: In function ‘extract_absolute_path_from_notification’:
rb_change.c:47:16: error: ‘_MAX_FNAME’ undeclared (first use in this function)
rb_change.c:47:16: note: each undeclared identifier is reported only once for each function it appears in
rb_change.c:47:33: error: ‘_MAX_EXT’ undeclared (first use in this function)
Makefile:206: recipe for target `rb_change.o' failed
make: *** [rb_change.o] Error 1
Gem files will remain installed in /usr/lib/ruby/gems/1.9.1/gems/wdm-0.1.0 for inspection.
Results logged to /usr/lib/ruby/gems/1.9.1/gems/wdm-0.1.0/ext/wdm/gem_make.out
A colleague of mine had an issue with wdm the other day.
We fixed it by downloading the Ruby DevKit (Not sure if you already had this installed).
I found some pretty decent step by steps online, I'll paste them here - hope they help
Development kit is here: http://rubyinstaller.org/downloads/
Download the Development Kit and install it in say c:\devkit.
Open a command window and type c:.
Change folders by typing cd devkit.
Type ruby dk.rb init to generate the config.yml file to be used later.
Your installed Rubies will be listed there (only those installed by a RubyInstaller package are detected at present). This needs to be done only once.
Finally type, ruby dk.rb install for DevKit enhance your installed Rubies. This needs to be done only once.
Confirm your Ruby environment is correctly using the DevKit by running:
gem install wdm --platform=ruby
It’s crucial that you include the --platform=ruby option to force RubyGems to build the native gem rather than potentially installing an incorrect binary gem.

Having difficulty installing ruby-filemagic gem on new RHEL6 server

It appears to be looking for the libmagic.so.1 file. I have that file. It is located in /usr/lib64. I am not running this installation as the root user.
I am also using rvm and Bundler. This is the result of my "bundle" command, when it gets to the ruby-filemagic line in my Gemfile:
[server#mine ext]$ ruby extconf.rb --with-magiclib
checking for magic_open() in -ltrue... no
*** ERROR: missing required library to compile this module
*** 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.
UPDATE:
Here are the results of the mkmf.log:
have_library: checking for magic_open() in -ltrue... -------------------- no
"gcc -o conftest -I. -I/usr/local/rvm/rubies/ruby-1.8.7-p358/lib/ruby/1.8/x86_64-linux -I. -g -O2 -fPIC conftest.c -L. -L/usr/local/rvm/rubies/ruby-1.8.7-p358/lib -Wl,-R/usr/local/rvm/rubies/ruby-1.8.7-p358/lib -L. -rdynamic -Wl,-export-dynamic -lruby-static -ltrue -lrt -ldl -lcrypt -lm -lc"
conftest.c: In function ‘t’:
conftest.c:3: error: ‘magic_open’ undeclared (first use in this function)
conftest.c:3: error: (Each undeclared identifier is reported only once
conftest.c:3: error: for each function it appears in.)
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { void ((*volatile p)()); p = (void ((*)()))magic_open; return 0; }
/* end */
"gcc -o conftest -I. -I/usr/local/rvm/rubies/ruby-1.8.7-p358/lib/ruby/1.8/x86_64-linux -I. -g -O2 -fPIC conftest.c -L. -L/usr/local/rvm/rubies/ruby-1.8.7-p358/lib -Wl,-R/usr/local/rvm/rubies/ruby-1.8.7-p358/lib -L. -rdynamic -Wl,-export-dynamic -lruby-static -ltrue -lrt -ldl -lcrypt -lm -lc"
/usr/bin/ld: cannot find -ltrue
collect2: ld returned 1 exit status
checked program was:
/* begin */
1: /*top*/
2: int main() { return 0; }
3: int t() { magic_open(); return 0; }
/* end */
I can't figure out what to do to make this work.
Had same problem on Ubuntu 12.04. Just installed libmagic-dev package through following command:
sudo apt-get install libmagic-dev
On a Mac, using homebrew:
sudo brew install libmagic
I needed to do:
yum install file-devel
That apparently contains the libmagic header files that the filemagic ruby gem required in order to compile. It worked like a champ after that.
I had the same problem on OpenSuse 11.3. This helped:
zypper install file-devel

compiler error while installing rubygem 'mysql2' in Ruby 1.9.2 over CentOS 64-bit

a CentOS 64-bit Server with Ruby 1.8.7 & 1.9.2
{{no RVM, need it without RVM...
currently all Ruby1.9.2 binaries are ruby19 and similarly accessible,
so no mapping of gem-path or anything of that sort is there}}
is giving error while installing gem 'mysql2' ...
I have all dependencies installed and all are 64-bit versions ...
All error are of kind {./client.h:13:
error: redefinition of typedef
‘rb_unblock_function_t’}
Could {#warning rubysig.h is obsolete}
be a reason for this?
Console Capture:
#gem19 install mysql2 -v 0.2.7 -- --with-mysql-dir=/usr/bin --with-mysql-config=/usr/bin/mysql_config --with-mysql-include=/usr/include/mysql
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/usr/bin/ruby19 extconf.rb --with-mysql-dir=/usr/bin --with-mysql-config=/usr/bin/mysql_config --with-mysql-include=/usr/include/mysql
checking for rb_thread_blocking_region()... no
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile
make
gcc -I. -I/usr/include/ruby-1.9.1/x86_64-linux -I/usr/include/ruby-1.9.1/ruby/backward -I/usr/include/ruby-1.9.1 -I. -DHAVE_MYSQL_H -DHAVE_ERRMSG_H -DHAVE_MYSQLD_ERROR_H -I/usr/include/mysql -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -mtune=generic -Wall -fno-strict-aliasing -fPIC -Wall -funroll-loops -o result.o -c result.c
In file included from ./client.h:11,
from ./mysql2_ext.h:39,
from result.c:1:
/usr/include/ruby-1.9.1/ruby/backward/rubysig.h:14:2: warning: #warning rubysig.h is obsolete
In file included from ./mysql2_ext.h:39,
from result.c:1:
./client.h:13: error: redefinition of typedef ‘rb_unblock_function_t’
/usr/include/ruby-1.9.1/ruby/intern.h:754: error: previous declaration of ‘rb_unblock_function_t’ was here
./client.h:14: error: redefinition of typedef ‘rb_blocking_function_t’
/usr/include/ruby-1.9.1/ruby/intern.h:755: error: previous declaration of ‘rb_blocking_function_t’ was here
./client.h:20: error: static declaration of ‘rb_thread_blocking_region’ follows non-static declaration
/usr/include/ruby-1.9.1/ruby/intern.h:759: error: previous declaration of ‘rb_thread_blocking_region’ was here
./client.h: In function ‘rb_thread_blocking_region’:
./client.h:23: warning: ‘rb_thread_blocking_region_begin’ is deprecated (declared at /usr/include/ruby-1.9.1/ruby/backward/rubysig.h:31)
./client.h:25: warning: ‘rb_thread_blocking_region_end’ is deprecated (declared at /usr/include/ruby-1.9.1/ruby/backward/rubysig.h:32)
In file included from ./mysql2_ext.h:39,
from result.c:1:
./client.h:41:7: warning: no newline at end of file
make: *** [result.o] Error 1
This is caused by a patch they introduced on the gem in order for it to run in Ruby 1.8 but it is not needed on Ruby 1.9.
To deactivated this "fix" and be able to install the gem you can define a flag for the compiler:
gem install mysql2 -- --with-cflags=\"-DHAVE_RB_THREAD_BLOCKING_REGION\"
The problem is in the extconf/mkmf section:
rb_thread_blocking_region()... no
But Ruby 1.9.2 defines rb_thread_blocking_region (unless you built Ruby
with some funky set of ifdef's and edits I'm not aware of).
Check your mkmf.log file. It should show you that Ruby failed
to compile/link the conftest.c file that tests for
rb_thread_blocking_region. The reason why is that libcrypt.a
has a dependency on libfreebl3, but the library isn't getting
referenced on the link line.
I fixed the problem by editing /usr/local/lib/ruby/1.9.1/i686-linux/rbconfig.rb like so:
- CONFIG["LIBS"] = "-lpthread -lrt -ldl -lcrypt -lm "
+ CONFIG["LIBS"] = "-lpthread -lrt -ldl -lcrypt -lfreebl3 -lm "
I was able to build the mysql2 gem after. No need to install rvm, etc.
What I did to fix it was to re-install Ruby via RVM. There no more errors after that.
Alternatively, remove the block in client.h that is trying to emulate rb_thread_blocking_region for Ruby 1.8 and you'll be good to go.

Resources