Обсуждение: pgsql and lion : not taking good header at compilation.

Поиск
Список
Период
Сортировка

pgsql and lion : not taking good header at compilation.

От
Pierre-Henry Frohring
Дата:
Hello,

I'm doing my first steps with postgre, and it seems that the Lion (10.7.4) install of postgre interferes with my install of postgre (9.1.4).

Here's a sample of the program i'm writing:

------------------------------------------------------------------------
int main () 
{

  // Params of connection to establish
  const char * keywords[] = {"dbname", "user", '\0'};
  const char * values[] = {"mydb", "postgresDB", '\0'};

  // Check server state
  switch (PQpingParams (keywords, values, 0))
    {
        // some stuff
    }
...
}
------------------------------------------------------------------------

Here the error message :
------------------------------------------------------------------------
g++ db_test.o -o db_test -L /usr/local/pgsql/bin -lpq
Undefined symbols for architecture x86_64:
  "_PQpingParams", referenced from:
      _main in db_test.o
ld: symbol(s) not found for architecture x86_64
------------------------------------------------------------------------

My guess :  g++ compile with the "old" version of postgre because if i remove PQpingParams (introduced in 9.1), it compiles.

My question : how to compile with my install of postgre ? 

(my install is standard :  
./configure
gmake
su
gmake install
)


Many thinks for giving me a hand on this one!
Pierre

Re: pgsql and lion : not taking good header at compilation.

От
Tom Lane
Дата:
Pierre-Henry Frohring <pierre.julienr@gmail.com> writes:
> I'm doing my first steps with postgre, and it seems that the Lion (10.7.4) install of postgre interferes with my
installof postgre (9.1.4). 

First off, it's "postgres" not "postgre".

> g++ db_test.o -o db_test -L /usr/local/pgsql/bin -lpq
> Undefined symbols for architecture x86_64:
>   "_PQpingParams", referenced from:
>       _main in db_test.o
> ld: symbol(s) not found for architecture x86_64

Most likely you need -L /usr/local/pgsql/lib not .../bin.  Use "otool -L"
on the resulting executable to verify that it's linked to the right
libpq.dylib file.

            regards, tom lane

Re: pgsql and lion : not taking good header at compilation.

От
James Hartley
Дата:
On Mon, Jul 2, 2012 at 3:31 AM, Pierre-Henry Frohring <pierre.julienr@gmail.com> wrote:
Here the error message :
------------------------------------------------------------------------
g++ db_test.o -o db_test -L /usr/local/pgsql/bin -lpq
Undefined symbols for architecture x86_64:
  "_PQpingParams", referenced from:
      _main in db_test.o
ld: symbol(s) not found for architecture x86_6
 
"Undefined symbols" means that the linker has not been able to resolve all references encountered in the code when attempting to construct the executable binary. 

You were half-way to the solution when you found out that commenting out the call to a PostgreSQL-specific function resulted in successful compilation *and linking*. 

 The fundamental problem is that the linker was unable to find the library containing function PQpingParams().  Tom is correct in noticing that the path provided is most likely incorrect.  Once you correct this library path, the linker should be able to create the desired binary.  Until the linker can find a library which defines this symbol, you will continue to see "undefined symbol" errors.