首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在windows starpack下为tdbc::mysql和tdbc::postgres包含dll的最佳方法是什么?

在windows starpack下为tdbc::mysql和tdbc::postgres包含dll的最佳方法是什么?
EN

Stack Overflow用户
提问于 2013-10-26 21:44:02
回答 2查看 377关注 0票数 1

包tdbc::mysql和tdbc::postgresql需要dll、libmysql.dll和libpq.dll。有什么最好的方法将这个dll包含到单个星包中呢?

目前,我使用的是以下pkgIndex.tcl:

代码语言:javascript
复制
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解释器使用的。我得到以下代码:

代码语言:javascript
复制
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的临时文件夹。

EN

回答 2

Stack Overflow用户

发布于 2013-10-26 23:26:58

如果没有管理员的访问权限,将文件复制到c:\windows\system32的“解决方案”将无法工作,而大多数从Windows开始的应用程序都没有这种访问权限。(您必须选择"run“),那么system32目录中较新的文件呢?你只要换掉它们。

一些替代办法:

  • 将所有dll您自己复制到一个临时目录,切换到该目录并加载dll(利用您查看的事实。(如在窗口): 如果需要tdbc::postgres 1.0.0 [列表应用{dir}{dir}{ set _ cd [file join $::env(TEMP) tclfile秒]文件mkdir $dest foreach dll -dir $dir *.dll { file copy $dll $dest } set cwd pwd cd $dest catch {源文件联接$dir tdbcpostgres.tcl加载文件连接$dest tdbpostgres100.dll tdbcpostgres }选择cd $cwd返回-options $opt $res } $dir] 但我们该如何清理这一切?
  • 将dll编译到星包中。这很难。
  • 自己编译扩展,这样它就没有任何依赖项了。我不知道该怎么做。
  • 自己加载每个所需的dll。这是我最喜欢的解决方案,但它需要twapi: 如果需要tdbc::postgres 1.0.0 [列表应用{dir}{ package {dir}{ package twapi foreach dll glob -dir $dir *.dll { ::twapi::load_library $dll }源文件join $dir tdbcpostgres.tcl load file join $dir tdbcpostgres 100.dll tdbcpostgres} $dir]
票数 1
EN

Stack Overflow用户

发布于 2013-10-27 00:54:25

这个技巧的主要问题是它需要对系统目录进行写访问。你不会想那样做的。但是,您可以使用这样的事实:如果库找不到引导符号,load就不会撤销它的加载。(这与Tcl通常的“在故障模式下尽可能干净”模型不同,但在这里非常有用。)

代码语言:javascript
复制
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。我想,这是一项相当多的工作,我还没有试过。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19612231

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档