Chapter3.Loading pgtcl into an Application
Prev |  | Next

# Chapter3.Loading pgtcl into an Application

本章では､貴兄の応用譜上で如何にpgtclを使うかを記述する｡pgtcl命令を使う前に､ Tcl応用譜内にlibpgtcl外部函数を積込まねばならない｡ これを行うには､三つの方法があるが､PostgreSQLの依頼先外部函数の libpq への 依存性があり注意を要する｡ This chapter describes how to use pgtcl with your Tcl application. Before using pgtcl commands, you must load the `libpgtcl` library into your Tcl application. There are three approaches to doing this, but care must be taken because of the dependency on the PostgreSQL client library `libpq`.

本章では､pgtclを伴って作成された Tcl と Tcl/Tk 殻の pgtclsh と pgwish を記載する｡ This chapter also describes pgtclsh and pgwish, which are Tcl and Tcl/Tk shells built with pgtcl.

本章は､pgtcl の pgtcl-ng 実装にのみ適用する｡他の実装については､含まれてた説明書を参照されたい｡ This chapter only applies to the pgtcl-ng implementation of pgtcl. For other implementations, check the included documentation.

## 3.1.Tcl梱包命令の使用 Using the Tcl Package Command

pgtcl 外部函数を積込む為にTcl梱包命令を使う事ができる｡ これは､系上にpgtclを使う多数の応用譜がある時に､特に推奨される方法である｡ その為には､ libpgtcl 外部函数と､搭載されるpkgIndex.tcl 梱包 索引ファイル を要す｡もし､これらのファイルが適切に搭載されると､貴兄の応用譜では､これを利用できる: You can use the Tcl `package` command to load the pgtcl library. This is the recommended approach, especially if you have multiple applications using pgtcl on your system. For this to work, you need the `libpgtcl` library and the `pkgIndex.tcl` package index file installed. If these files are installed properly, your application can use:

    package require Pgtcl

この記述でpgtcl libraryが使える｡但し､特定の版を要する応用譜の場合はこの様に: to load the pgtcl library. Or, if your application requires a specific version:

    package require Pgtcl 2.1

これは､Tcl応用譜内に梱包を積込む好ましい方法である､但し､ 幾つかの搭載準備を要す｡特に､外部函数と梱包索引ファイルは､必ず､ Tcl $auto_path か $tcl_pkgPath ディレクトリーの仔ディレクトリーに､搭載されなばならない｡ この梱包の搭載の典型的な位置は: /usr/lib/tcl8.5/pgtcl2.1/ ｡ (註意 仔ディレクトリ名(ここではpgtcl2.1)は､外部函数名に合致しなくてもよい､又､ 慣習により､版のたった二つの部分のみを含む｡tclは梱包を捜す為にその梱包外部函数の全ての仔ディレクトリーを見る｡) 更なる詳細は､pkgMkIndex上のtcl説明書を参照されたい｡ This is the preferred method for loading a package into a Tcl application, however it does require some installation setup. Specifically, the library and package index file must be installed into a subdirectory of the Tcl `$auto_path` or `$tcl_pkgPath` directories. A typical location for installation of this package might be: `/usr/lib/tcl8.5/pgtcl2.1/` . (Note the subdirectory name (here `pgtcl2.1`), does not need to match the library name, and by convention includes only the two parts of the version. Tcl looks in all subdirectories of its package library directory to find packages.) Refer to the Tcl documentation on pkgMkIndex for more details.

更に､libpgtcl外部函数を搭載する為に､ 系共有外部函数積込み機能によって判る場所に､libpq外部函数を､積込まねばならない｡ libpqを libpgtclに同伴した梱包ディレクトリーに搭載しても働かない｡ In addition to installing the `libpgtcl` library, you must install the `libpq` library in a location where it will be found by the system shared library loader. Just installing `libpq` in the package directory along with `libpgtcl` will not work.

### 3.1.1."Package require" setup for Unix-like systems

On Unix-like systems, either install the `libpq` library into a well-known system directory such as `/usr/local/lib`, or install it somewhere else. If you install it somewhere else, either modify the system loader configuration (typically using a command like ldconfig), or use the environment variable `LD_LIBRARY_PATH` to tell the system loader where to find it.

On some Unix-like systems, such as Linux, the path where `libpq` was found when building `libpgtcl` is stored in the `libpgtcl` library (as `rpath`). This lets the system find the library even if it isn't in a well-known system directory or pointed to by `LD_LIBRARY_PATH`. The other methods of finding the library still apply, if it is not in the stored location.

### 3.1.2."Package require" setup for Windows

Windows系の上では､Borland C++ Builder (BCC)により構築する方法と､ MinGWにより構築する方法の､二通りの可能性がある｡ それらには､異なる依存関係がある｡ There are two possibilities for `libpgtcl` on Windows systems: one built with Borland C++ Builder (BCC), and one built with MinGW. These have different dependencies.

### Note

pgtclng-1.8.0版以降は､MinGW道具のみ試験して使用した｡ BCC 製の版についての情報は参照のみである｡ Starting with pgtclng-1.8.0, only MinGW tools are being tested and used. Information about BCC-built versions is included for reference only.

Windows系上でMinGW製のlibpgtcl.dllを使うには､全EnterpriseDB PostgreSQL 二進数ディレクトリーが利用可能で､且つ､PATH上になければならない､ 理由は､外部函数に多重の依存があるから｡ libpq.dll への利用の提供は十分ではない｡ (もし､必要なら､実行譜を除いてそれを除去できる｡) On Windows systems, using the MinGW-built `libpgtcl.dll`, the entire EnterpriseDB PostgreSQL `bin` directory needs to be available and on the PATH, because there are multiple dependent libraries. Supplying access to `libpq.dll` is not sufficient. (If necessary, you can trim this down by removing the executables.)

Windows系上でBCC製のlibpgtcl.dllを使うには､ blibpq.dll 外部函数をPATH環境変数内 に名付けられたディレクトリーに装着する｡(註意 BCCで製作されたlibpqの版は "blibpq.dll"と 呼ばれる｡) もし､ blibpq.dll 外部函数が同じディレクトリーにTcl記述譜解釈実行譜 tclsh.exe や wish.exeと して装着されていると､又動く｡註意: 単純にblibpq.dllを同じディレクトリーに libpgtcl.dllとして置く のは､ pkgIndex.tcl を使う仕掛けがない限り動かない｡PATH上に見付けられねばならない｡ On Windows systems, using the BCC-built `libpgtcl.dll`, install the `blibpq.dll` library into a directory named in the `PATH` environment variable. (Note that the version of libpq built with BCC is called "blibpq.dll".) It will also work if the `blibpq.dll` library is installed in the same directory as the Tcl script interpreter `tclsh.exe` or `wish.exe`. Note: It will not work to simply place blibpq.dll in the same directory as libpgtcl.dll, unless the trick below using pkgIndex.tcl is used. It must be found on the PATH.

他の blibpq.dll 外部函数の装着法は､ pgtcl 梱包ディレクトリ内にそれを置き､ それを積込む修正 package index ファイルを使う｡ これが､Win系用の pkgIndex.tcl package index ファイルで､梱包ディレクトリーから両方の外部函数を積込む事ができる｡ (このファイルは､pkgIndex.tcl.win32として源譜配布に含まれている) Another option for installing the `blibpq.dll` library is to place it in the pgtcl package directory, and use a modified package index file to load it. Here is a `pkgIndex.tcl` package index file for Windows systems which enables loading both libraries from the package directory. (This file is included in the source distribution as `pkgIndex.tcl.win32`.)

    # Tcl package index file, version 1.1
    # This is a modified package index file for Pgtcl on Windows. libpgtcl needs
    # libpq, but libpq has to be found on PATH. So this modifies PATH before
    # loading libpgtcl, then restores PATH after. This allows you to store
    # both libpgtcl.dll and [b]libpq.dll in the package directory.

    proc Pgtcl__load_with_path {dir} {
      global env
      set save_path $env(PATH)
      append env(PATH) ";$dir"
      load [file join $dir libpgtcl.dll]
      set env(PATH) $save_path
    }
    package ifneeded Pgtcl 1.7.2 [list Pgtcl__load_with_path $dir]

Prev |  | Next
2.4.Building and Installing on MacOS 10 | Home | 3.2.Directly loading `libpgtcl`