[英]How to tell TCL and TK that default `.tcl` language files should be searched locally?
当您从源代码手动编译 TCL/Tk 或仅从ActiveState 安装它时,您会在 TCL/Tk 安装文件夹中获得以下结构:
+- bin
+- tcl85.dll
+- tk85.dll
//...
+- lib/
+- tcl8.5/
//All TCL files (.tcl)
+- tk8.5/
//All TK files (.tcl)
//...
因此,当您编译您的某些应用程序并将其链接到 TCL 和 TK DLL 时,该 DLL 会搜索相对于 tham(到 DLL 的)目录../lib/tk8.5 和../lib/tcl8 中的所有 TCL/TK 文件。 5. 这使得分发您的应用程序而不必让最终用户安装 TCL 和 TK 变得相当困难。
我想分发我的 C++ 应用程序。
我使用CPPTK作为默认的 GUI 布局。
我想让它成为可能,这样最终用户就不需要安装 TCL 和 TK。 我想为他们提供包含 TK 和 TCL .TCL
源文件的文件夹,这些文件将位于与我的应用程序相关的某个目录中,例如extras/TCL
和extras/TK
。 如何告诉 TK 和 TCL DLL 源文件夹在哪里? TK 和 TCL API function 的名称是什么? 是否有任何特殊的 cpptk 功能?
更新所以我用下一个文件夹结构尝试了Donal Fellows 的答案。
app/
+- app.exe
+- tcl85.dll
+- tk85.dll
+- extras/
+- tcl/
//All TCL files you can find in TCL install folder/ lib/tcl8.5
+- tk/
//All TK files you can find in TCL install folder/ lib/tk8.5
我的代码看起来像:
#include <stdio.h>
#include "cpptk/cpptk.h"
using namespace Tk;
int main(int, char *argv[])
{
static char* str = "set extrasDir [file dirname [info nameofexecutable]]/extras\n"
"# Now use it to load some code...\n"
"source $extrasDir/tcl/init.tcl\n"
"# Another way to load code, using all *.tk files from a directory:\n"
"foreach tkFile [glob -nocomplain -directory $extrasDir/tk *.tk] {\n"
" source $tkFile\n"
"}\n";
// This next part is in a function or method...
//std::string script("the script to evaluate goes here");
std::string result = Tk::details::Expr(str,true); // I think this is correct
std::cout<< result << std::endl;
std::cin.get();
Tk::init(argv[0]);
button(".b") -text("Say Hello");
pack(".b") -padx(20) -pady(6);
Tk::runEventLoop();
std::cin.get();
}
它编译但在 cpptkbase.cc 的第 36 行失败
顺便说一句:我使用这个 html\js 应用程序来获取 char 字符串。
如果你有一个包含你的二进制文件的目录,并且你想定位那些相对于它的 Tcl 文件,像这样:
yourapp1.0/ +- yourapp.exe +- extras/ +- tcl/ +- foo.tcl +- bar.tcl +- tk/ +- grill.tk
然后您可以编写 Tcl 代码来查找这些脚本。 该代码将是这样的:
set extrasDir [file dirname [info nameofexecutable]]/extras
# Now use it to load some code...
source $extrasDir/tcl/foo.tcl
source $extrasDir/tcl/bar.tcl
# Another way to load code, using all *.tk files from a directory:
foreach tkFile [glob -nocomplain -directory $extrasDir/tk *.tk] {
source $tkFile
}
如果您使用脚本作为主程序,但在上述结构中进行了其他设置,您将使用$argv0
(一个特殊的全局变量)而不是[info nameofexecutable]
。 或者可能是[info script]
(尽管有一些警告)。
[编辑]:要使该代码与 C++/Tk 一起使用,您需要更加棘手。 特别是,您需要获得一些额外的胆量:
#include "cpptk.h" // might need "base/cpptkbase.h" instead
#include <string>
// This next part is in a function or method...
std::string script("the script to evaluate goes here");
std::string result = Tk::details::Expr(script,true); // I think this is correct
我应该警告我不经常写 C++ 所以这很有可能不起作用; 它只是基于阅读 C++/Tk 源代码并进行猜测。 买者自负。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.