아마도 소스 컴파일해서 설치하기 보다는 rpm 으로 설치한듯 한 느낌이 드는군요. 컴파일시 옵션을 어떻게 주셨는지요. gcc 컴파일시 사용한 명령어를 옵션과 합쳐서 보여 주시기 바랍니다.
>>이태웅 님께서 쓰시길<<
:: 안녕하세요~
::
:: 소스는...
:: #include <stdio.h>
:: #include "/usr/include/pgsql/libpq/fe.h"
:: // 이상한데 깔려있어서리.. //;
::
:: void exit_nicely(PGconn *conn)
:: {
:: PQfinish(conn);
:: exit(1);
:: }
::
:: int main()
:: {
:: char *pghost,
:: *pgport,
:: *pgoptions,
:: *pgtty;
:: char *dbName, *login, *pwd;
:: int nFields;
:: int i, j;
::
:: /* FILE *debug; */
::
:: PGconn *conn;
:: PGresult *res;
::
:: /*
:: * begin, by setting the parameters for a backend connection if the
:: * parameters are null, then the system will try to use reasonable
:: * defaults by looking up environment variables or, failing that,
:: * using hardwired constants
:: */
:: pghost = NULL; /* host name of the backend server */
:: pgport = NULL; /* port of the backend server */
:: pgoptions = NULL; /* special options to start up the backend
:: * server */
:: pgtty = NULL; /* debugging tty for the backend server */
:: dbName = "imsi";
:: login = "imsi";
:: pwd = NULL;
::
:: /* make a connection to the database */
:: conn = PQsetdbLogin(pghost, pgport, pgoptions, pgtty, dbName, login, pwd);
::
:: /*
:: * check to see that the backend connection was successfully made
:: */
:: if (PQstatus(conn) == CONNECTION_BAD)
:: {
:: fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
:: fprintf(stderr, "%s", PQerrorMessage(conn));
:: exit_nicely(conn);
:: }
::
:: /* debug = fopen("/tmp/trace.out","w"); */
:: /* PQtrace(conn, debug); */
::
:: /* start a transaction block */
:: res = PQexec(conn, "select * from imsi;");
:: if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
:: {
:: fprintf(stderr, "select command failed\n");
:: PQclear(res);
:: exit_nicely(conn);
:: }
:: /*
:: * should PQclear PGresult whenever it is no longer needed to avoid
:: * memory leaks
:: */
:: PQclear(res);
::
:: /* first, print out the attribute names */
:: nFields = PQnfields(res);
:: for (i = 0; i < nFields; i++)
:: printf("%/15s", PQfname(res, i));
:: printf("\n\n");
::
:: /* next, print out the instances */
:: for (i = 0; i < PQntuples(res); i++)
:: {
:: for (j = 0; j < nFields; j++)
:: printf("%/15s", PQgetvalue(res, i, j));
:: printf("\n");
:: }
:: PQclear(res);
::
:: /* close the connection to the database and cleanup */
:: PQfinish(conn);
::
:: /* fclose(debug); */
:: return 0;
::
:: }
::
:: 에러메시지는..
:: cc imsi.c
:: /tmp/ccbd6W2N.o: In function `exit_nicely':
:: /tmp/ccbd6W2N.o(.text+0x8): undefined reference to `PQfinish'
:: /tmp/ccbd6W2N.o: In function `main':
:: /tmp/ccbd6W2N.o(.text+0x78): undefined reference to `PQsetdbLogin'
:: /tmp/ccbd6W2N.o(.text+0x89): undefined reference to `PQstatus'
:: /tmp/ccbd6W2N.o(.text+0xb3): undefined reference to `PQerrorMessage'
:: /tmp/ccbd6W2N.o(.text+0xe6): undefined reference to `PQexec'
:: /tmp/ccbd6W2N.o(.text+0xfd): undefined reference to `PQresultStatus'
:: /tmp/ccbd6W2N.o(.text+0x128): undefined reference to `PQclear'
:: /tmp/ccbd6W2N.o(.text+0x140): undefined reference to `PQclear'
:: /tmp/ccbd6W2N.o(.text+0x14c): undefined reference to `PQnfields'
:: /tmp/ccbd6W2N.o(.text+0x179): undefined reference to `PQfname'
:: /tmp/ccbd6W2N.o(.text+0x1b5): undefined reference to `PQntuples'
:: /tmp/ccbd6W2N.o(.text+0x1ed): undefined reference to `PQgetvalue'
:: /tmp/ccbd6W2N.o(.text+0x227): undefined reference to `PQclear'
:: /tmp/ccbd6W2N.o(.text+0x233): undefined reference to `PQfinish'
:: collect2: ld returned 1 exit status
:: 이렇게 나와요.
:: libpq.so 이 파일은 /usr/lib에 깔려있답니다. 기본으로 /etc/ld.so.conf에 있는 폴더.. 예전엔 이렇
:: 지 않았던것 같은데.. 역시 다른 사람의 컴퓨터는 정말.....
|