Re: /usr/bin/ld: cannot find [...] when compiling

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Janek Sendrowski" <janek12(at)web(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: /usr/bin/ld: cannot find [...] when compiling
Date: 2013-11-24 18:56:31
Message-ID: 6319.1385319391@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Janek Sendrowski" <janek12(at)web(dot)de> writes:
> The file test.c just inlcudes: #include "postgres.h".
> root(at)ubuntu:/usr/include/postgresql/9.3/server# gcc test.c
> In file included from postgres.h:48:0,
> from test.c:1:
> utils/elog.h:69:28: fatal error: utils/errcodes.h: No such file or directory
> compilation terminated.

> If elog.h file only includes "errcodes.h" without /utils, it's working.
> It's the same With all files I'm including.

> Makefile:
> PROGRAM = test
> DATA = test.c

> PG_CONFIG = pg_config
> PGXS := $(shell $(PG_CONFIG) --pgxs)
> include $(PGXS)

> root(at)ubuntu:/usr/include/postgresql/9.3/server# make
> gcc -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -fPIC -pie -I/usr/include/mit-krb5 -DLINUX_OOM_ADJ=0 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -L/usr/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -L/usr/lib/mit-krb5 -L/usr/lib/i386-linux-gnu/mit-krb5 -L/usr/lib/i386-linux-gnu -Wl,--as-needed -lpgport -lpgcommon -lxslt -lxml2 -lpam -lssl -lcrypto -lkrb5 -lcom_err -lgssapi_krb5 -lz -ledit -lcrypt -ldl -lm -o test

It looks like the problem is that there aren't any Postgres-specific -I
flags in the make command. After a bit of poking around in the pgxs code
I think the reason why not is that you're using the PROGRAM target instead
of MODULES or MODULE_big. This might be a bug in our makefiles, but it's
also somewhat defensible, in that if you're building a standalone program
then you aren't going to have access to any server internal functions.

What's your actual goal here --- are you trying to build a server
extension or a standalone program? If the former, you should be using the
MODULES or MODULE_big targets. If the latter, you should probably be
including postgres_fe.h not postgres.h.

> /usr/bin/ld: cannot find -lxslt
> /usr/bin/ld: cannot find -lxml2
> /usr/bin/ld: cannot find -lpam
> /usr/bin/ld: cannot find -ledit
> collect2: ld returned 1 exit status
> make: *** [test] Error 1

> I don't know where to get these devel-packages.

Since you let slip that you're using ubuntu, they probably have names
ending in -dev not -devel.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2013-11-24 19:05:39 Re: /usr/bin/ld: cannot find [...] when compiling
Previous Message Janek Sendrowski 2013-11-24 17:32:37 Re: /usr/bin/ld: cannot find [...] when compiling