gem install - how to link additional library to native library (krb5 to ruby-pg)

Hello!

I'm trying to install ruby-pg gem on my Ubuntu 9.04
So I'm typing:
sudo gem install ruby-pg

Gem is downloaded from remote repository, but linking of native
library fails with following results:

Questions are:
1. Why --with-opt-lib adds entry to -L ?

because that's what it's supposed to do: it's for telling extconf
"here is an extra path to search for libraries"

2. How to add additonal library (krb5), which should be linked to
native library?

not sure about that. you may be able to play around with the usual set
of environment variables (LDFLAGS etc.)

Fred

Hello!

I’m trying to install ruby-pg gem on my Ubuntu 9.04

So I’m typing:

sudo gem install ruby-pg

Gem is downloaded from remote repository, but linking of native

library fails with following results:


Building native extensions. This could take a while…

ERROR: Error installing ruby-pg:

    ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb install ruby-pg

checking for main() in -lpq… no

*** extconf.rb failed ***

Could not create Makefile due to some reason, probably lack of

necessary libraries and/or headers.

— cut —

mkmf.log says:


have_library: checking for main() in -lpq… -------------------- no

"cc -o conftest -I. -I/usr/lib/ruby/1.8/i486-linux -I. -I/usr/include/

postgresql -D_FILE_OFFSET_BITS=64 -fno-strict-aliasing -g -g -O2 -

fPIC conftest.c -L. -L/usr/lib -L/usr/lib -L. -Wl,-Bsymbolic-

functions -rdynamic -Wl,-export-dynamic -lruby1.8-static -lpq -

lpthread -ldl -lcrypt -lm -lc"

/usr/lib/libpq.so: undefined reference to

`krb5_cc_get_principal@krb5_3_MIT’

/usr/lib/libpq.so: undefined reference to

`gss_import_name@gssapi_krb5_2_MIT’

/usr/lib/libpq.so: undefined reference to

`gss_release_buffer@gssapi_krb5_2_MIT’

— cut —

It looks, that libpq5 installed on my Ubuntu needs libkrb53 package.

Libkrb I have in standard place: /usr/lib, but krb5 library has to be

added to cc command as additional library.

So I’m using option “with-opt-lib” to “gem install”:

sudo gem install ruby-pg – --with-opt-lib=krb5

Now krb5 library appeared in -L command instead of -l (see below log),

what caused that native library still cannot be linked.

Here is mkmf.log:


have_library: checking for main() in -lpq… -------------------- no

"cc -o conftest -I. -I/usr/lib/ruby/1.8/i486-linux -I. -I/usr/include/

postgresql -D_FILE_OFFSET_BITS=64 -fno-strict-aliasing -g -g -O2 -

fPIC conftest.c -L. -L/usr/lib -L/usr/lib -Lkrb5 -L. -Wl,-Bsymbolic-

functions -rdynamic -Wl,-export-dynamic -lruby1.8-static -lpq -

lpthread -ldl -lcrypt -lm -lc"

/usr/lib/libpq.so: undefined reference to

`krb5_cc_get_principal@krb5_3_MIT’

/usr/lib/libpq.so: undefined reference to

`gss_import_name@gssapi_krb5_2_MIT’

/usr/lib/libpq.so: undefined reference to

`gss_release_buffer@gssapi_krb5_2_MIT’

/usr/lib/libpq.so: undefined reference to

`krb5_free_unparsed_name@krb5_3_MIT’

— cut —

Questions are:

  1. Why --with-opt-lib adds entry to -L ?

  2. How to add additonal library (krb5), which should be linked to

native library?

My environment is:

ubuntu 9.04

ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]

gem --version 1.3.1

ruby-pg-0.7.9.2008.01.28

postgresql 8.3.7-1

libpq5

libkrb53

Regards,

Mariusz Wojtysiak

It appears that you cannot reference libpq which is the C application programmer’s interface to PostgreSQL. In the above, you have libpq5 installed on your system but the Ruby gem, ruby-pg, is looking for libpg. To correct this issue, you might want to take a look at the ruby-pg git repository here:

http://github.com/maxime/ruby-pg-for-ruby-1.9.1rc2/tree/master

Finally, I don’t know enough about the ruby-pg gem in regards to configuring the Kerberos.

-Conrad

Hello!

I’m trying to install ruby-pg gem on my Ubuntu 9.04

So I’m typing:

sudo gem install ruby-pg

Gem is downloaded from remote repository, but linking of native

library fails with following results:


Building native extensions. This could take a while…

ERROR: Error installing ruby-pg:

    ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb install ruby-pg

checking for main() in -lpq… no

*** extconf.rb failed ***

Could not create Makefile due to some reason, probably lack of

necessary libraries and/or headers.

— cut —

mkmf.log says:


have_library: checking for main() in -lpq… -------------------- no

"cc -o conftest -I. -I/usr/lib/ruby/1.8/i486-linux -I. -I/usr/include/

postgresql -D_FILE_OFFSET_BITS=64 -fno-strict-aliasing -g -g -O2 -

fPIC conftest.c -L. -L/usr/lib -L/usr/lib -L. -Wl,-Bsymbolic-

functions -rdynamic -Wl,-export-dynamic -lruby1.8-static -lpq -

lpthread -ldl -lcrypt -lm -lc"

/usr/lib/libpq.so: undefined reference to

`krb5_cc_get_principal@krb5_3_MIT’

/usr/lib/libpq.so: undefined reference to

`gss_import_name@gssapi_krb5_2_MIT’

/usr/lib/libpq.so: undefined reference to

`gss_release_buffer@gssapi_krb5_2_MIT’

— cut —

It looks, that libpq5 installed on my Ubuntu needs libkrb53 package.

Libkrb I have in standard place: /usr/lib, but krb5 library has to be

added to cc command as additional library.

So I’m using option “with-opt-lib” to “gem install”:

sudo gem install ruby-pg – --with-opt-lib=krb5

Now krb5 library appeared in -L command instead of -l (see below log),

what caused that native library still cannot be linked.

Here is mkmf.log:


have_library: checking for main() in -lpq… -------------------- no

"cc -o conftest -I. -I/usr/lib/ruby/1.8/i486-linux -I. -I/usr/include/

postgresql -D_FILE_OFFSET_BITS=64 -fno-strict-aliasing -g -g -O2 -

fPIC conftest.c -L. -L/usr/lib -L/usr/lib -Lkrb5 -L. -Wl,-Bsymbolic-

functions -rdynamic -Wl,-export-dynamic -lruby1.8-static -lpq -

lpthread -ldl -lcrypt -lm -lc"

/usr/lib/libpq.so: undefined reference to

`krb5_cc_get_principal@krb5_3_MIT’

/usr/lib/libpq.so: undefined reference to

`gss_import_name@gssapi_krb5_2_MIT’

/usr/lib/libpq.so: undefined reference to

`gss_release_buffer@gssapi_krb5_2_MIT’

/usr/lib/libpq.so: undefined reference to

`krb5_free_unparsed_name@krb5_3_MIT’

— cut —

Questions are:

  1. Why --with-opt-lib adds entry to -L ?

  2. How to add additonal library (krb5), which should be linked to

native library?

My environment is:

ubuntu 9.04

ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]

gem --version 1.3.1

ruby-pg-0.7.9.2008.01.28

postgresql 8.3.7-1

libpq5

libkrb53

Regards,

Mariusz Wojtysiak

It appears that you cannot reference libpq which is the C application programmer’s interface to PostgreSQL. In the above, you have libpq5 installed on your system but the Ruby gem, ruby-pg, is looking for libpg. To correct this issue, you might want to take a look at the ruby-pg git repository here:

http://github.com/maxime/ruby-pg-for-ruby-1.9.1rc2/tree/master

Finally, I don’t know enough about the ruby-pg gem in regards to configuring the Kerberos.

-Conrad

I have forgot to mention Kerberos needs to be enabled when you build Postgres server because I don’t think this is done by default.

-Conrad

It appears that you cannot reference libpq which is the C application
programmer's interface to PostgreSQL. In the above, you have libpq5
installed on your system but the Ruby gem, ruby-pg, is looking for libpg.

I don't add libpq during installing ruby-pg. It is added automatically
by installation string (extconf.rb).
I think it has sense, because ruby-pg use native library written in C
in order to access PostgreSQL. But first this native library has to be
compiled using libpq...

I also installed on my Ubuntu libpgsql-ruby package, which contains
pg.so in /usr/lib/ruby/1.8/i486-linux.
But I have no idea how to force "gem install ruby-pg" to use pg.so
instead of libpq (if it's correct direction).

Maybe pg.so is this native library, which cannot be linked during
installation ruby-pg?
I yes, then how can I force "gem install ruby-pg" to use this already
installed pg.so, instead of compiling it?

Finally, I don't know enough about the ruby-pg gem in regards to configuring
the Kerberos.

In fact I don't use kerberos in my project! But libpq depends on
libkrb :-(, so I have linking errors.

It appears that you cannot reference libpq which is the C application

programmer’s interface to PostgreSQL. In the above, you have libpq5

installed on your system but the Ruby gem, ruby-pg, is looking for libpg.

I don’t add libpq during installing ruby-pg. It is added automatically

by installation string (extconf.rb).

I think it has sense, because ruby-pg use native library written in C

in order to access PostgreSQL. But first this native library has to be

compiled using libpq…

Please reread my statement above about what’s going on. In short,

your build fails because it cannot locate the pg library.

I also installed on my Ubuntu libpgsql-ruby package, which contains

pg.so in /usr/lib/ruby/1.8/i486-linux.

But I have no idea how to force “gem install ruby-pg” to use pg.so

instead of libpq (if it’s correct direction).

You misunderstood what I was trying to explain to you. The reference to the pq library

needs to be corrected for what ruby-pg expects. For example,

have_library: checking for main() in -lpq… -------------------- no

The above error message says that it could not find libpq on your system in the

configure step on the build.

Maybe pg.so is this native library, which cannot be linked during

installation ruby-pg?

I yes, then how can I force “gem install ruby-pg” to use this already

installed pg.so, instead of compiling it?

Again, you have libpq5 installed and the Ruby gem, ruby-pg, is looking

libpg. For example, libpg is not equal to libpq.

Finally, I don’t know enough about the ruby-pg gem in regards to configuring

the Kerberos.

In fact I don’t use kerberos in my project! But libpq depends on

libkrb :-(, so I have linking errors.

libpq doesn’t depend on libkrb unless you build Postgres with the Kerberos feature

enabled. Did you enable Postgres with Kerberos when you installed it?

-Conrad

> I also installed on my Ubuntu libpgsql-ruby package, which contains
> pg.so in /usr/lib/ruby/1.8/i486-linux.
> But I have no idea how to force "gem install ruby-pg" to use pg.so
> instead of libpq (if it's correct direction).

You misunderstood what I was trying to explain to you. The reference to the
pq library
needs to be corrected for what ruby-pg expects. For example,

have_library: checking for main() in -lpq... -------------------- no

The above error message says that it could not find libpq on your system in
the
configure step on the build.

I'm not so sure about that. What this means is that the test program
that tried to test linking against libpq failed to compile. Most
obviously this would be because libpq can't be found but doesn't look
like it in this case. Like I said before i would play around with the
LDFLAGS environment variable and see if you could use that to make it
link against the kerberos library.

The libpgsql-ruby library is basically the ruby postgres bindings (at
least one of them - there have been a number of them over time, all
with rather similar names), but installed via your package manager
rather than as a gem. Assuming this library is the set of bindings
that you do want you don't need the gem - you'd just end up with the
same code installed twice, once as a gem and once not (although the
timestamp in the version number for it makes it look quite old).

Fred

Please reread my statement above about what's going on. In short,
your build fails because it cannot locate the pg library.

Problem is that looking into mkmf.log I don't see any problem with pg
library. Nothing like -lpg in cc statement... Instead of pg, pq is
used. Looking into extconf.rb script (used by "gem install ruby-pg") I
also see that pq is used there. Not pg...

You misunderstood what I was trying to explain to you. The reference to the
pq library
needs to be corrected for what ruby-pg expects. For example,

have_library: checking for main() in -lpq... -------------------- no

The above error message says that it could not find libpq on your system in
the
configure step on the build.

It looks like this at the first sight. But mkmf.log says more details
about this error:
/usr/lib/libpq.so: undefined reference to `krb5_cc_get_principal

So libpq was found, but it refer to krb5, which cannot be found.
I know that krb5 cannot be found and I'm trying to add -lkrb5 somehow
in a legal way (without modifying gem installation scripts) - for
example by adding some option to command "gem install".

libpq doesn't depend on libkrb unless you build Postgres with the Kerberos
feature
enabled. Did you enable Postgres with Kerberos when you installed it?

That may be a problem. I installed Postgres from Ubuntu repository,
where Kerberos is enabled by default.
So: my own Postgres compilation witout Kerberos should solve the
problem (although
it wont be the best solution).

I'm not so sure about that. What this means is that the test program
that tried to test linking against libpq failed to compile. Most
obviously this would be because libpq can't be found but doesn't look
like it in this case. Like I said before i would play around with the
LDFLAGS environment variable and see if you could use that to make it
link against the kerberos library.

I agree with you: compilation of test program fails.

Following sequence:
export LDFLAGS=-lkrb5
sudo gem install ruby-pg

changes nothing. "-lkrb5" wasn't added to cc command in mkmf.log

The libpgsql-ruby library is basically the ruby postgres bindings (at
least one of them - there have been a number of them over time, all
with rather similar names), but installed via your package manager
rather than as a gem. Assuming this library is the set of bindings
that you do want you don't need the gem - you'd just end up with the
same code installed twice, once as a gem and once not (although the
timestamp in the version number for it makes it look quite old).

Yes. That could be a solution. But this package installed only /usr/
lib/ruby/1.8/i486-linux/pg.so library and some documents. None rb
script was installed! I feel that without .rb scripts I cannot use
ruby-pg adapter in my rails.

I think I will try to compile myself postgres + libpq without
Kerberos.
Then ruby-pg should be installed without problems.

Conrad, Fred: Thanks for your help!

> I'm not so sure about that. What this means is that the test program
> that tried to test linking against libpq failed to compile. Most
> obviously this would be because libpq can't be found but doesn't look
> like it in this case. Like I said before i would play around with the
> LDFLAGS environment variable and see if you could use that to make it
> link against the kerberos library.

I agree with you: compilation of test program fails.

Following sequence:
export LDFLAGS=-lkrb5
sudo gem install ruby-pg

changes nothing. "-lkrb5" wasn't added to cc command in mkmf.log

I'd try fiddling with some of the other flags then. CCFLAGS etc.

Fred

Not necessarily. While sometimes you might only implement the
bottlenecks in c with some ruby that makes the C bits prettier there
are plenty of things which are just a blob of native code.

Fred

CCFLAGS also didn't help, but...

I just tried to use libpgsql-ruby package as you mentioned and it
works!!!

This is some kind of magic for me: plain pg.so library is used
directly by rails without any .rb wrappers.
Never think that something is impossible, especially in Ruby :slight_smile:

Thanks a lot!

@ Mariusz Wojtysiak

This is good to here.

@ Frederick Cheung

Is there documentation as to what database adapters people should

be using for the various database engines on a particular OS? For example,

something like

Operating Systems

Database Engine Mac OS Linux Windows …

PostgreSQL

MySQL

SQLite sudo gem install sqlite3-ruby

-Conrad