在CentOS上如何编译安装psqlODBC与问题解决

CentOS 7 上编译安装 psqlODBC 时,遇到了几个问题,记录解决方法以备不时之需。

wget https://ftp.postgresql.org/pub/odbc/versions/src/psqlodbc-10.01.0000.tar.gz
tar -xvzf psqlodbc-10.01.0000.tar.gz
cd psqlodbc-10.01.0000/
./configure
make

make 后报错:

make  all-am
make[1]: Entering directory `/root/psqlodbc-10.01.0000'
/bin/sh ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.   -I/usr/include -I/usr/local/pgsql/include -I/usr/local/pgsql/include/internal -DUNICODE_SUPPORT  -g -O2 -Wall -MT psqlodbcw_la-info.lo -MD -MP -MF .deps/psqlodbcw_la-info.Tpo -c -o psqlodbcw_la-info.lo `test -f 'info.c' || echo './'`info.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I/usr/include -I/usr/local/pgsql/include -I/usr/local/pgsql/include/internal -DUNICODE_SUPPORT -g -O2 -Wall -MT psqlodbcw_la-info.lo -MD -MP -MF .deps/psqlodbcw_la-info.Tpo -c info.c  -fPIC -DPIC -o .libs/psqlodbcw_la-info.o
In file included from info.c:19:0:
psqlodbc.h:112:17: fatal error: sql.h: No such file or directory
 #include 
                 ^
compilation terminated.
make[1]: *** [psqlodbcw_la-info.lo] Error 1
make[1]: Leaving directory `/root/psqlodbc-10.01.0000'
make: *** [all] Error 2

参考 sql.h header file missing though unixODBC is installed 后,可通过安装 ODBC 的开发包解决:

yum install unixODBC-devel

继续编译,然后报错:

make  all-am
make[1]: Entering directory `/root/psqlodbc-10.01.0000'
/bin/sh ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.   -I/usr/include -I/usr/local/pgsql/include -I/usr/local/pgsql/include/internal -DUNICODE_SUPPORT  -g -O2 -Wall -MT psqlodbcw_la-odbcapi30.lo -MD -MP -MF .deps/psqlodbcw_la-odbcapi30.Tpo -c -o psqlodbcw_la-odbcapi30.lo `test -f 'odbcapi30.c' || echo './'`odbcapi30.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I/usr/include -I/usr/local/pgsql/include -I/usr/local/pgsql/include/internal -DUNICODE_SUPPORT -g -O2 -Wall -MT psqlodbcw_la-odbcapi30.lo -MD -MP -MF .deps/psqlodbcw_la-odbcapi30.Tpo -c odbcapi30.c  -fPIC -DPIC -o .libs/psqlodbcw_la-odbcapi30.o
odbcapi30.c:120:1: error: conflicting types for 'SQLColAttribute'
 SQLColAttribute(SQLHSTMT StatementHandle,
 ^
In file included from psqlodbc.h:112:0,
                 from odbcapi30.c:21:
/usr/include/sql.h:609:24: note: previous declaration of 'SQLColAttribute' was here
     SQLRETURN  SQL_API SQLColAttribute(SQLHSTMT StatementHandle,
                        ^
make[1]: *** [psqlodbcw_la-odbcapi30.lo] Error 1
make[1]: Leaving directory `/root/psqlodbc-10.01.0000'
make: *** [all] Error 2

谷歌了一阵子,发现有类似的问题,但都没给出比较官方的解决方法,看见到网友直接注释掉了该函数的定义,参见 这里

vim /usr/include/sql.h
#if 0
    SQLRETURN  SQL_API SQLColAttribute(SQLHSTMT StatementHandle,
                                        SQLUSMALLINT ColumnNumber, SQLUSMALLINT FieldIdentifier,
                                        SQLPOINTER CharacterAttribute, SQLSMALLINT BufferLength,
                                        SQLSMALLINT *StringLength, SQLLEN *NumericAttribute );
#endif

继续编译,错误也是继续:

make  all-am
make[1]: Entering directory `/root/psqlodbc-10.01.0000'
/bin/sh ./libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.   -I/usr/include -I/usr/local/pgsql/include -I/usr/local/pgsql/include/internal -DUNICODE_SUPPORT  -g -O2 -Wall -MT psqlodbcw_la-odbcapi30w.lo -MD -MP -MF .deps/psqlodbcw_la-odbcapi30w.Tpo -c -o psqlodbcw_la-odbcapi30w.lo `test -f 'odbcapi30w.c' || echo './'`odbcapi30w.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I/usr/include -I/usr/local/pgsql/include -I/usr/local/pgsql/include/internal -DUNICODE_SUPPORT -g -O2 -Wall -MT psqlodbcw_la-odbcapi30w.lo -MD -MP -MF .deps/psqlodbcw_la-odbcapi30w.Tpo -c odbcapi30w.c  -fPIC -DPIC -o .libs/psqlodbcw_la-odbcapi30w.o
odbcapi30w.c:266:1: error: conflicting types for 'SQLColAttributeW'
 SQLColAttributeW(SQLHSTMT hstmt,
 ^
In file included from /usr/include/sqlext.h:2184:0,
                 from psqlodbc.h:113,
                 from odbcapi30w.c:15:
/usr/include/sqlucode.h:29:19: note: previous declaration of 'SQLColAttributeW' was here
 SQLRETURN SQL_API SQLColAttributeW(
                   ^
make[1]: *** [psqlodbcw_la-odbcapi30w.lo] Error 1
make[1]: Leaving directory `/root/psqlodbc-10.01.0000'
make: *** [all] Error 2

按照之前的做法,继续注释掉吧:

vim /usr/include/sqlucode.h
#if 0
SQLRETURN SQL_API SQLColAttributeW(
        SQLHSTMT                hstmt,
        SQLUSMALLINT    iCol,
        SQLUSMALLINT    iField,
        SQLPOINTER              pCharAttr,
        SQLSMALLINT             cbCharAttrMax,  
        SQLSMALLINT     *pcbCharAttr,
        SQLLEN          *pNumAttr);     
#endif

//#define       SQLColAttribute         SQLColAttributeW

编译成功,make install 后成功:

make[1]: Entering directory `/root/psqlodbc-10.01.0000'
 /usr/bin/mkdir -p '/usr/local/lib'
 /bin/sh ./libtool   --mode=install /usr/bin/install -c   psqlodbcw.la psqlodbca.la '/usr/local/lib'
libtool: install: /usr/bin/install -c .libs/psqlodbcw.so /usr/local/lib/psqlodbcw.so
libtool: install: /usr/bin/install -c .libs/psqlodbcw.lai /usr/local/lib/psqlodbcw.la
libtool: install: /usr/bin/install -c .libs/psqlodbca.so /usr/local/lib/psqlodbca.so
libtool: install: /usr/bin/install -c .libs/psqlodbca.lai /usr/local/lib/psqlodbca.la
libtool: finish: PATH="/usr/local/pgsql/bin:/usr/local/pgsql/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/bird/.local/bin:/home/bird/bin:/sbin" ldconfig -n /usr/local/lib
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,-rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
make[1]: Nothing to be done for `install-data-am'.
make[1]: Leaving directory `/root/psqlodbc-10.01.0000'
Advertisements

分类:默认目录, PostgreSQL

Tagged as: ,

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  更改 )

Google+ photo

You are commenting using your Google+ account. Log Out /  更改 )

Twitter picture

You are commenting using your Twitter account. Log Out /  更改 )

Facebook photo

You are commenting using your Facebook account. Log Out /  更改 )

w

Connecting to %s