包tdbc::mysql和tdbc::postgresql需要dll、libmysql.dll和libpq.dll。有什么最好的方法将这个dll包含到单个星包中呢?
目前,我使用的是以下pkgIndex.tcl:
if {[catch {package require Tcl 8.6}]} {
return
}
package ifneeded tdbc::postgres 1.0.0 [list apply {{dir} {
if { $::tcl_platform(os) eq "Windows NT" &&
($::tcl_platform(machine) eq "intel" ||
$::tcl_platform(machine) ne "amd64") } {
foreach n {libpq libeay32 ssleay32 comerr32 gssapi32
k5sprt32 krb5_32 libiconv-2 libintl-8} {
file copy -force [file join $dir ${n}.dll] \
[file join $::env(WINDIR) System32 ${n}.dll]
}
}
source [file join $dir tdbcpostgres.tcl]
load [file join $dir tdbcpostgres100.dll] tdbcpostgres
}} $dir]但这看起来很难看。
我试图找到一种方法将必要的库复制到解释器用来加载dll的临时文件夹中。但是通过检查Tcl源代码,找出临时目录的名称对于脚本来说是不可能的。
更新:在当前时间,我决定使用来确定临时文件夹的名称,该临时文件夹是由Tcl解释器使用的。我得到以下代码:
if {[catch {package require Tcl 8.6}]} {
return
}
package ifneeded tdbc::postgres 1.0.0 [list apply {{dir} {
if { $::tcl_platform(os) eq "Windows NT" &&
($::tcl_platform(machine) eq "intel" ||
$::tcl_platform(machine) eq "amd64") } {
package require twapi
set _ [file dirname [lindex [lsearch -inline -index 1 -glob \
[twapi::get_process_modules [twapi::get_current_process_id] -path] \
{*/twapi_base*.dll}] 1]]
if { $_ eq "." } {
error "couldn't find temp folder name for tdbc::postgres support library"
}
foreach fn [glob -types f -tails -directory $dir "*.dll"] {
if { [string match -nocase "tdbcpostgres*" $fn] } continue
file copy -force [file join $dir $fn] [file join $_ $fn]
}
} {
set _ [pwd]
}
source [file join $dir tdbcpostgres.tcl]
set tpwd [pwd]
cd $_
catch { load [file join $dir tdbcpostgres100.dll] tdbcpostgres } r o
cd $tpwd
return -options $o $r
}} $dir]但是,在程序退出后删除临时文件仍然存在问题。我只看到一个解决方案:在程序开始时扫描文件夹$::env(TEMP)并尝试删除所有命名为TCLXXXXXXXX的临时文件夹。
发布于 2013-10-26 23:26:58
如果没有管理员的访问权限,将文件复制到c:\windows\system32的“解决方案”将无法工作,而大多数从Windows开始的应用程序都没有这种访问权限。(您必须选择"run“),那么system32目录中较新的文件呢?你只要换掉它们。
一些替代办法:
发布于 2013-10-27 00:54:25
这个技巧的主要问题是它需要对系统目录进行写访问。你不会想那样做的。但是,您可以使用这样的事实:如果库找不到引导符号,load就不会撤销它的加载。(这与Tcl通常的“在故障模式下尽可能干净”模型不同,但在这里非常有用。)
package ifneeded tdbc::postgres 1.0.0 [list apply {{dir} {
global tcl_platform
if {$tcl_platform(os) eq "Windows NT" && $tcl_platform(machine) ne "amd64"} {
foreach n {libpq libeay32 ssleay32 comerr32 gssapi32
k5sprt32 krb5_32 libiconv-2 libintl-8} {
if {![file exist [file join $::env(WINDIR) System32 ${n}.dll]]} {
# Leverage Tcl's built-in loading magic
catch {load [file join $dir ${n}.dll]}
}
}
}
source [file join $dir tdbcpostgres.tcl]
load [file join $dir tdbcpostgres100.dll] tdbcpostgres
}} $dir]这仍然不是很优雅,但是拦截真正的依赖加载机制是非常困难的;预加载只是简单得多。(如果用户已经拥有了特定的库,我也停止了代码的操作。)
正确的解决方法是构建一个具有其他依赖项作为静态库的tdbcpostgres100.dll。我想,这是一项相当多的工作,我还没有试过。
https://stackoverflow.com/questions/19612231
复制相似问题