草庐IT

FreeTDS库文件之在BC-Linux服务器上的编译安装

枫叶2000 2023-10-12 原文


《FreeTDS库文件之C++代码中的简单应用》
  在安装FreeTDS库文件之前,我查阅了好多的文章,讲述的都是freetds-0.9x的一些老版本的安装。而没有找到关于freetds最新版本的安装说明的。我想大概是我搜索方式不对吧。无奈只能不断摸索,最终将GitHub上下载的最新版本的FreeTDS源代码编译成功了。
  写本文的当前时间为2023年2月15日,GitHub上freetds的源码链接:https://github.com/FreeTDS/freetds。目前发布的最新的Releases版本是1.3.17。
  新版本的源码和旧版本的源码最大的区别在于没有了现成的configureMakefile文件,因此当我们下载了最新的freetds项目源码解压后,一下子就懵了。感觉查阅过的资料都是骗人的,说好的configure文件呢?我们查阅的资料包括官网,都在说,运行configure文件生成Makefile文件,然后make & make install 就安装成功了,多么简单啊。实际,对小白的我来说,configure文件都没有,还谈什么编译和安装,只有懵逼相伴。
  好了,扯了一堆,其实都是我自己的感受,我对于Linux也是仅限于用过几个命令的层次而已。对于小白的我在这种情况下也只能默默的看官网的说明,用百度翻译一句一句的翻译,过程相当难受。好在最终成功编译了出来。

  • 编译FreeTDS项目源码需要的环境

FreeTDS官网的User Guide用户指南第2章:Build FreeTDS(http://www.freetds.org/userguide/build.html) 中,介绍了

[4] Versions used for this release
* autoconf (GNU Autoconf) 2.69
* automake (GNU automake) 1.15
* ltmain.sh (GNU libtool) 2.4.6

即要想编译源码,Linux环境需要安装有GNU版本的autoconf、automake、libtool工具。所以第一步就是安装这些程序:

[root@localhost freetds]# yum install autoconf
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
>>>>>>>>>>>>>> 中间的安装过程省略 <<<<<<<<<<<<<<
Running transaction
  正在安装    : m4-1.4.16-10.el7.x86_64                                              1/3 
  正在安装    : perl-Data-Dumper-2.145-3.el7.x86_64                                  2/3 
  正在安装    : autoconf-2.69-11.el7.noarch                                          3/3 
  验证中      : perl-Data-Dumper-2.145-3.el7.x86_64                                  1/3 
  验证中      : m4-1.4.16-10.el7.x86_64                                              2/3 
  验证中      : autoconf-2.69-11.el7.noarch                                          3/3 

已安装:
  autoconf.noarch 0:2.69-11.el7

作为依赖被安装:
  m4.x86_64 0:1.4.16-10.el7                                                         perl-Data-Dumper.x86_64 0:2.145-3.el7
完毕!
[root@localhost freetds]# autoconf --version
autoconf (GNU Autoconf) 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+/Autoconf: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by David J. MacKenzie and Akim Demaille.
[root@localhost freetds]# 
[root@localhost freetds]# yum install automake
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
>>>>>>>>>>>>>> 中间的安装过程省略 <<<<<<<<<<<<<<
Running transaction
  正在安装    : perl-Test-Harness-3.28-3.el7.noarch                                  1/2 
  正在安装    : automake-1.13.4-3.el7.noarch                                         2/2 
  验证中      : perl-Test-Harness-3.28-3.el7.noarch                                  1/2 
  验证中      : automake-1.13.4-3.el7.noarch                                         2/2 

已安装:
  automake.noarch 0:1.13.4-3.el7

作为依赖被安装:
  perl-Test-Harness.noarch 0:3.28-3.el7

完毕!
[root@localhost freetds]# automake --version
automake (GNU automake) 1.13.4
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv2+: GNU GPL version 2 or later <http://gnu.org/licenses/gpl-2.0.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Tom Tromey <tromey@redhat.com>
       and Alexandre Duret-Lutz <adl@gnu.org>.
[root@localhost freetds]# 

[root@localhost freetds]# yum install libtool
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
>>>>>>>>>>>>>> 中间的安装过程省略 <<<<<<<<<<<<<<
Running transaction
  正在安装    : libtool-2.4.2-22.el7_3.x86_64                                        1/1 
  验证中      : libtool-2.4.2-22.el7_3.x86_64                                        1/1

已安装:
  libtool.x86_64 0:2.4.2-22.el7_3

完毕!
[root@localhost freetds]# libtool --version
libtool (GNU libtool) 2.4.2
Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996

Copyright (C) 2011 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@localhost freetds]# 

用上面的安装的版本也是可以编译成功的,当然你也可以指定安装推荐的版本。

  • 下载FreeTDS项目源码

这里用git工具克隆项目源码到本地仓库。首先登陆GitHub,在搜索框中键入freetds,点击搜索就可以找到FreeTDS项目,打开仓库FreeTDS/freetds(https://github.com/FreeTDS/freetds),点击绿色code按钮,选择HTTPS页,可以得到代码链接:https://github.com/FreeTDS/freetds.git

  1. 用git命令克隆项目源码到本地路径

git工具是Linux系统自带的工具,可以直接使用。
命令:git init myfreetds : 创建一个本地git仓库,名字为myfreetds,当然名字可以自己起,效果就是在当前目录下生成一个myfreetds名字的文件夹,里面有构成仓库的组成文件,都是隐藏文件。
命令:git clone https://github.com/FreeTDS/freetds.git :拉取GitHub上的源代码到本地。效果就是下载了freetds源代码到myfreetds文件夹中。
如下所示:

[root@localhost code]# git init myfreetds
初始化空的 Git 版本库于 /home/fenghx/code/downtest/myfreetds/.git/
[root@localhost code]# ls
myfreetds
[root@localhost code]# cd myfreetds/
[root@localhost myfreetds]# ls
[root@localhost myfreetds]# ls -al
总用量 0
drwxr-xr-x. 3 root root  18 2月  15 16:13 .
drwxr-xr-x. 3 root root  23 2月  15 16:13 ..
drwxr-xr-x. 7 root root 119 2月  15 16:13 .git
[root@localhost myfreetds]# git clone https://github.com/FreeTDS/freetds.git
正克隆到 'freetds'...
remote: Enumerating objects: 58058, done.
remote: Counting objects: 100% (1286/1286), done.
remote: Compressing objects: 100% (501/501), done.
remote: Total 58058 (delta 927), reused 1098 (delta 785), pack-reused 56772
接收对象中: 100% (58058/58058), 14.51 MiB | 33.00 KiB/s, done.
处理 delta 中: 100% (48275/48275), done.
[root@localhost myfreetds]# ls
freetds
[root@localhost myfreetds]# cd freetds/
[root@localhost freetds]# ls
AUTHORS.md  ChangeLog       config.rpath  COPYING_LIB.txt  doc           freetds.spec.in  INSTALL.GIT.md  interfaces    m4           misc           NEWS.md   PWD.in     README.Windows  src      Thanks-0.95  TODO.freddy  vms
autogen.sh  CMakeLists.txt  configure.ac  COPYING.txt      freetds.conf  include          INSTALL.md      locales.conf  Makefile.am  mkinstalldirs  phptests  README.md  samples         tds.dox  Thanks-1.0   TODO.md      win32
[root@localhost freetds]# 

现在源码就下载好了,代码下载还是有点耗时的,请耐心等待。如果出现下载失败的情况,重新下载就可以了。

  1. 编译源代码并安装

由于没有configureMakefile文件,所以我们无法进行编译,于是想configure文件应该是由其它的执行文件生成的,但是不知道应该执行哪个文件。这些就要说些经验了,我发现里面有一个autogen.sh文件,我之前做嵌入式的时候,也是在Linux环境下编译代码的,生成的可执行文件就是以.sh为后缀的。于是我想应该是这个文件了。打开查看一下发现

#!/bin/sh
# Run this to generate all the initial makefiles, etc.

# $Id: autogen.sh,v 1.10 2011-03-22 17:54:04 jklowden Exp $

# From automake.info:
#
#    Many packages come with a script called `bootstrap.sh' or
# `autogen.sh', that will just call `aclocal', `libtoolize', `gettextize'
# or `autopoint', `autoconf', `autoheader', and `automake' in the right
# order.  Actually this is precisely what `autoreconf' can do for you.
# If your package has such a `bootstrap.sh' or `autogen.sh' script,
# consider using `autoreconf'.  That should simplify its logic a lot
# (less things to maintain, yum!), it's even likely you will not need the
# script anymore, and more to the point you will not call `aclocal'
# directly anymore.

srcdir=`dirname $0`
PKG_NAME="FreeTDS."

# If autoreconf encounters an error, it might be because this is the 
# very first time it was run, meaning that some files e.g. config.sub
# are missing.  We retry with --install (and perhaps we should 
# try --force, too).  
#
# Revision 1.6 was the last one not to use autoreconf.  If you can't get
# this (simpler) one to work, you might try that one. 

(       cd $srcdir
        echo running `which autoreconf` in `pwd`: 
        autoreconf || autoreconf --install
) || exit

#conf_flags="--enable-maintainer-mode --enable-compile-warnings" #--enable-iso-c

if test x$NOCONFIGURE = x; then
  echo Running $srcdir/configure $conf_flags "$@" '...' \
        | tr ' ' \\n \
        | sed  's/^-/   &/'
  $srcdir/configure $conf_flags "$@" \
  && echo Now type \`make\' to compile $PKG_NAME
else
  echo Skipping configure process.
fi



"autogen.sh" 44L, 1576C                                                                                  1,1          全部

文中第一句 “Run this to generate all the initial makefiles, etc.” 意思是“运行该文件以生成所有初始makefile等。”,那应该就是这个文件了,文章接下的 “From automake.info” 中大概的意思是,许多软件包都附带一个名为“bootstrap.sh”或“autogen.sh”的脚本,他们会按正确的顺序调用“aclocal”、“libtoolize”、“gettextize”或“autopoint”、“autoconf”、“autoheader”和“automake”。这大大简化程序编译和配置的操作。

那大概流程应该就是:

  • 首先运行 autogen.sh 生成 初始的 configure & Makefile
  • 然后通过 configure 配置自定义的 Makefile 文件
  • 最后 make & make install

我在运行autogen.sh文件的时候,会出现一个报错:
configure.ac:123: warning: macro 'AM_ICONV' not found in library
这个错误和文中提到的gettextize工具有关,因此我们需要先安装工具gettext程序。

安装命令: yum -y install gettext gettext-devel

安装到后面还有一个报错:
configure: error: required program 'gperf' not found.
所以我们还需要安装程序 gperf.

安装命令:yum -y install gperf

如果你在安装过程中没有出现这些错误,可以直接跳过,看后面的内容。
下面让我们运行 autogen.sh 脚本

[root@localhost freetds]# ./autogen.sh
running /usr/bin/autoreconf in /home/fenghx/code/myfreetds/freetds:
......
>>>>>>>>>>>>>> 中间的安装过程省略 <<<<<<<<<<<<<<
......
Running
./configure
...
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
......
>>>>>>>>>>>>>> 中间的安装过程省略 <<<<<<<<<<<<<<
......
configure: debug enabled
checking CFLAGS for gcc -Wdeclaration-after-statement... -Wdeclaration-after-statement
done
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating include/freetds/version.h
config.status: creating include/tds_sysdep_public.h
config.status: creating include/freetds/sysdep_types.h
config.status: creating Makefile
config.status: creating include/Makefile
......
>>>>>>>>>>>>>> 中间的安装过程省略 <<<<<<<<<<<<<<
......
config.status: executing depfiles commands
config.status: executing libtool commands
Now type `make' to compile FreeTDS.
[root@localhost freetds]# ^C
[root@localhost freetds]# 

如果出现上面最后一行:Now type `make' to compile FreeTDS.,恭喜你,你已经成功生成了configure文件和Makefile文件。如下

[root@localhost freetds]# ls
aclocal.m4  autom4te.cache  compile       config.rpath   configure        COPYING.txt  freetds.conf     include         install-sh  locales.conf  Makefile     misc           NEWS.md   README.md       src          Thanks-0.95  TODO.md
AUTHORS.md  ChangeLog       config.guess  config.status  configure.ac     depcomp      freetds.spec     INSTALL.GIT.md  interfaces  ltmain.sh     Makefile.am  missing        phptests  README.Windows  tds.dox      Thanks-1.0   vms
autogen.sh  CMakeLists.txt  config.log    config.sub     COPYING_LIB.txt  doc          freetds.spec.in  INSTALL.md      libtool     m4            Makefile.in  mkinstalldirs  PWD.in    samples         test-driver  TODO.freddy  win32
[root@localhost freetds]# 

此时生成的Makefile文件为默认的,初始的配置文件。因此我们还需要使用configure来配置我们自定义的Makfile文件。
根据官网的介绍,configure命令参数有很多,这里提三个:

  • --prefix=PREFIX :设置FreeTDS库文件安装的目录,默认为:/usr/local,命令行中将PREFIX替换为自定义的路径。
  • --with-tdsver=VER :指定FreeTDS的安装版本,默认为:auto,命令行中将VER替换为指定的版本号。这里的版本主要是根据不通的数据库版本来选择的,具体什么版本的freetds支持什么数据库可以查阅官网《用户指南》中第一章中 History of TDS Versions章节 (http://www.freetds.org/userguide/tdshistory.html)。具体支持配置的版本有哪些,可以通过执行./configure --help命令来查看。下面会说怎么看。
  • --enable-msdblib :这个选项按官网的解释不太好理解,其它资料解释为:允许Microsoft数据库函数库。

查看 FreeTDS 支持哪些版本的指定,如下:

[root@localhost freetds]# ./configure --help
`configure' configures FreeTDS 1.4.dev.20230215 to adapt to many kinds of systems.

Usage: ./configure [OPTION]... [VAR=VALUE]...

......
>>>>>>>>>>>>>> 中间的内容省略 <<<<<<<<<<<<<<
......
  --with-tdsver=VERSION   TDS protocol version (5.0/7.1/7.2/7.3/7.4/auto)
                          [auto]
 
......
>>>>>>>>>>>>>> 中间的内容省略 <<<<<<<<<<<<<<
......
Report bugs to the package provider.
[root@localhost freetds]#

可以看到当前可以指定的版本为 5.0/7.1/7.2/7.3/7.4,最高为7.4版本。由于我的数据库安装的是SQL Server2017 所以需要指定最高版本。

下面使用 configure 配置 Makefile 文件,这里我指定安装路径为默认路径,版本指定7.4,允许使用微软数据库函数库。

命令:./configure --prefix=/usr/local --with-tdsver=7.4 --enable-msdblib

[root@localhost freetds]# ./configure --prefix=/usr/local --with-tdsver=7.4 --enable-msdblib
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
......
>>>>>>>>>>>>>> 中间的内容省略 <<<<<<<<<<<<<<
......
configure: debug enabled
checking CFLAGS for gcc -Wdeclaration-after-statement... -Wdeclaration-after-statement
done
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating include/freetds/version.h
config.status: creating include/tds_sysdep_public.h
config.status: creating include/freetds/sysdep_types.h
config.status: creating Makefile
config.status: creating include/Makefile
......
>>>>>>>>>>>>>> 中间的内容省略 <<<<<<<<<<<<<<
......
config.status: executing libtool commands
[root@localhost freetds]# 

此时新的自定义的Makefile就生成了。

编译并安装

直接运行: make 命令进行编译,然后运行 make install命令进行安装即可,这里不在累赘。

需要说明的是,如果你不是通过git命令拉取的代码,而是直接下载的 .zip 或 .tar.gz 压缩包,那么在make和make install的时候会报一个查看历史提交记录失败的错误。如下
git log -1 '--pretty=format:%n<!ENTITY ug.dat......省略......
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
这些错误一般都出现在最后,此时所有的库都编译或是安装完成了,git需要查看提交的历史记录,但是你并没有本地仓库,也就没有提交的历史记录,所以失败了(我的理解)。这些错误不影响freetds的编译和安装,已经亲自测试了。

安装完成后会在/usr/local/include目录下生成头文件,其中有我们代码调用时需要的sybfront.h和sybdb.h头文件,以及编译时需要链接的库文件sybdb。

[root@localhost freetds]# ls /usr/local/lib
libct.a  libct.la  libct.so  libct.so.4  libct.so.4.0.0  libsybdb.a  libsybdb.la  libsybdb.so  libsybdb.so.5  libsybdb.so.5.1.0
[root@localhost freetds]# ls /usr/local/include/
bkpublic.h  cspublic.h  cstypes.h  ctpublic.h  odbcss.h  sqldb.h  sqlfront.h  sybdb.h  syberror.h  sybfront.h  tds_sysdep_public.h
[root@localhost freetds]# 

到这里开发软件所需的 FreeTDS 库文件就安装完成了。感谢您的查阅。


《FreeTDS库文件之C++代码中的简单应用》

有关FreeTDS库文件之在BC-Linux服务器上的编译安装的更多相关文章

  1. ruby - 使用 RubyZip 生成 ZIP 文件时设置压缩级别 - 2

    我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看ruby​​zip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d

  2. ruby - 其他文件中的 Rake 任务 - 2

    我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时

  3. ruby-on-rails - 在 Rails 中将文件大小字符串转换为等效千字节 - 2

    我的目标是转换表单输入,例如“100兆字节”或“1GB”,并将其转换为我可以存储在数据库中的文件大小(以千字节为单位)。目前,我有这个:defquota_convert@regex=/([0-9]+)(.*)s/@sizes=%w{kilobytemegabytegigabyte}m=self.quota.match(@regex)if@sizes.include?m[2]eval("self.quota=#{m[1]}.#{m[2]}")endend这有效,但前提是输入是倍数(“gigabytes”,而不是“gigabyte”)并且由于使用了eval看起来疯狂不安全。所以,功能正常,

  4. ruby-on-rails - Rails 3 中的多个路由文件 - 2

    Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题

  5. ruby - 具有身份验证的私有(private) Ruby Gem 服务器 - 2

    我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..

  6. ruby - 将差异补丁应用于字符串/文件 - 2

    对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl

  7. ruby - 如何将脚本文件的末尾读取为数据文件(Perl 或任何其他语言) - 2

    我正在寻找执行以下操作的正确语法(在Perl、Shell或Ruby中):#variabletoaccessthedatalinesappendedasafileEND_OF_SCRIPT_MARKERrawdatastartshereanditcontinues. 最佳答案 Perl用__DATA__做这个:#!/usr/bin/perlusestrict;usewarnings;while(){print;}__DATA__Texttoprintgoeshere 关于ruby-如何将脚

  8. ruby - 使用 Vim Rails,您可以创建一个新的迁移文件并一次性打开它吗? - 2

    使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta

  9. Ruby 写入和读取对象到文件 - 2

    好的,所以我的目标是轻松地将一些数据保存到磁盘以备后用。您如何简单地写入然后读取一个对象?所以如果我有一个简单的类classCattr_accessor:a,:bdefinitialize(a,b)@a,@b=a,bendend所以如果我从中非常快地制作一个objobj=C.new("foo","bar")#justgaveitsomerandomvalues然后我可以把它变成一个kindaidstring=obj.to_s#whichreturns""我终于可以将此字符串打印到文件或其他内容中。我的问题是,我该如何再次将这个id变回一个对象?我知道我可以自己挑选信息并制作一个接受该信

  10. ruby - 如何使用 Ruby aws/s3 Gem 生成安全 URL 以从 s3 下载文件 - 2

    我正在编写一个小脚本来定位aws存储桶中的特定文件,并创建一个临时验证的url以发送给同事。(理想情况下,这将创建类似于在控制台上右键单击存储桶中的文件并复制链接地址的结果)。我研究过回形针,它似乎不符合这个标准,但我可能只是不知道它的全部功能。我尝试了以下方法:defauthenticated_url(file_name,bucket)AWS::S3::S3Object.url_for(file_name,bucket,:secure=>true,:expires=>20*60)end产生这种类型的结果:...-1.amazonaws.com/file_path/file.zip.A

随机推荐