Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When postgres 9.3 was installed by apt, it doesn't work. #13

Closed
8398a7 opened this issue Aug 5, 2015 · 17 comments
Closed

When postgres 9.3 was installed by apt, it doesn't work. #13

8398a7 opened this issue Aug 5, 2015 · 17 comments

Comments

@8398a7
Copy link

8398a7 commented Aug 5, 2015

/usr/bin/ld: /opt/crystal/bin/../embedded/lib/../lib/libgc.a(os_dep.o): undefined reference to symbol '_end'
//lib/x86_64-linux-gnu/libcom_err.so.2: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
require "pg"
DB = PG.connect("postgres://user@localhost:5432/db")
result = DB.exec({Int32}, "select count(id) from users")
p result
  • ubuntu 14.04LTS
  • postgres 9.3.9
  • crystal 0.7.5

I want to know how to resolve this issue.

@will
Copy link
Owner

will commented Aug 5, 2015

This looks similar to #8 which is some sort of linking problem that we weren't able to get to the bottom of, unfortunately.

Just to make sure when you run pg_config all the values there are correct?

@8398a7
Copy link
Author

8398a7 commented Aug 5, 2015

I tried some pg_config value, but there were not correct.

It ran correctly after to 9.4 the postgres.
Despite pass the test with postgres 9.3 in travis, I wonder.

@will
Copy link
Owner

will commented Aug 5, 2015

The version of the server doesn't matter much as long as it's > 7.3 or so, the last time the protocol changed.

What I think happened is there was something not quite right with your local postgres setup, if pg_config was giving the wrong information, and when you updated to 9.4 you fixed that as a side-effect.

This project uses pg_config to find the appropriate directories to link against.

@8398a7
Copy link
Author

8398a7 commented Aug 7, 2015

I investigated the pg_config, there was a difference such as follows.

# postgres 9.3.9
INCLUDEDIR = /usr/include/postgresql
LIBDIR = /usr/lib
# postgres 9.4.4
INCLUDEDIR = /usr/include/postgresql
LIBDIR = /usr/lib/x86_64-linux-gnu

Therefore, I tried to rewrite the libpq.cr in this way with postgres 9.3.9, it was successful.

module PG
  @[Link(ldflags: "-lpq -I`pg_config --includedir` -L /usr/lib/x86_64-linux-gnu")]
  lib LibPQ

My postgres was installed by apt, therefore what is better to take action as good think.
What do you think?

@8398a7 8398a7 changed the title not working on ubuntu 14.04 When postgres was installed by apt, it doesn't work. Aug 7, 2015
@8398a7 8398a7 changed the title When postgres was installed by apt, it doesn't work. When postgres 9.3 was installed by apt, it doesn't work. Aug 7, 2015
@will
Copy link
Owner

will commented Aug 7, 2015

Did/do you have the libpq-dev package installed from apt?

@8398a7
Copy link
Author

8398a7 commented Aug 7, 2015

Yes, I have.

@ysbaddaden
Copy link
Contributor

I'm having this bug too, on a "clean" ubuntu trusty install. I never upgraded from another release and I only ever installed PostgreSQL 9.3 (but am up to date on updates and security).

The minimum snippet to reproduce is:

require "pg"
PG.connect("postgres://postgres:@localhost/")
  • it fails to compile with the official crystal DEB packages, which uses some embedded static libs (eg: libpcl.a, libgc.a, ...)
  • it passes if I compiled crystal myself, which uses shared libraries (so static libs may be a hint)
  • it passes with crystal test_pg.cr --link-flags "-L/usr/lib/x86_64-linux-gnu" (something seems required in that directory)

BTW: the -I includedir is unnecessary in the @Link definition since crystal doesn't care about headers files. Actually @[Link("pq")] is enough on Linux, except that we need the -L/usr/lib/x86_64-linux-gnu, even though libpq is installed in /usr/lib. Maybe libpq merely highlights a linking issue that is unrelated?

@ysbaddaden
Copy link
Contributor

Errata: it passes with -L/usr/lib/x86_64-linux-gnu because the linker no longer uses the embedded static libs from /opt/crystal/embedded/lib and instead uses shared libs from /usr/lib/x86_64-linux-gnu to compile the binary.

@ysbaddaden
Copy link
Contributor

@will
Copy link
Owner

will commented Aug 17, 2015

Is /usr/lib/x86_64-linux-gnu not the result of pg_config --libdir for you?

If it is the same, then I don't understand why the @[Link(ldflags: "-lpq -Ipg_config --includedir-Lpg_config --libdir")] line doesn't work (even if -I isn't necessary).

If it isn't the same, then I don't understand why your pg_config is returning incorrect data.

@ysbaddaden
Copy link
Contributor

No, pg_config --libdir states /usr/lib which is where libpq.{a,so} is indeed installed.

This seems to be a common linker bug, triggered by linking against libgc.a and libpq.so or libcom_err.so but doesn't happen when using libgc.so (or something like that).

@will
Copy link
Owner

will commented Aug 17, 2015

I checked with my Ubuntu-using colleges, and they have pg_config binaires that give the correct results

~$ pg_config --libdir
/usr/lib/x86_64-linux-gnu

Can you try something like

export PATH=/opt/PostgreSQL/9.3/bin/:$PATH

(or wherever the binaries are) to get a proper pg_config?

@fdr
Copy link
Contributor

fdr commented Aug 18, 2015

Hi,

@will asked me to have a look at how pg_config presents --libdir on Ubuntu. It looks like it has a useful value on my system:

$ pg_config --libdir
/usr/lib/x86_64-linux-gnu
$ cat /etc/issue.net 
Ubuntu 15.04

@fdr
Copy link
Contributor

fdr commented Aug 18, 2015

I use the PGDG packages.

@will will mentioned this issue Aug 23, 2015
@will
Copy link
Owner

will commented Aug 23, 2015

@fdr I've been able to reproduce this on an aws instance, and it also happens on the image b&p uses for slugc. I added your pubkey to the aws instance, can you help me track this down?

@will
Copy link
Owner

will commented Aug 24, 2015

So, @fdr and I tracked this down more, crystal-lang/crystal#1269

It explains why when the libdir isn't /usr/lib things work

@will will mentioned this issue Apr 17, 2016
@will
Copy link
Owner

will commented May 5, 2016

The driver is now native, so this problem is no longer relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants