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

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

[code lang=text]
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
[/code]

make 后报错:

[code lang=text]
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
[/code]

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

yum install unixODBC-devel

继续编译,然后报错:

[code lang=text]
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
[/code]

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

[code lang=text]
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
[/code]

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

[code lang=text]
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

[/code]

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

[code lang=text]
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
[/code]

编译成功,make install 后成功:

[code lang=text]
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′
[/code]

如无特殊说明,文章均为本站原创,转载请注明出处
源自: 王明军的博客
本文链接地址: 在CentOS上如何编译安装psqlODBC与问题解决
广告

Categories: 默认目录, PostgreSQL

Tagged as: ,

发表评论

This site uses Akismet to reduce spam. Learn how your comment data is processed.