gpt4 book ai didi

c++ - 如何告诉TCL和TK在本地搜索默认 `.tcl`语言文件?

转载 作者:太空宇宙 更新时间:2023-11-04 04:05:27 26 4
gpt4 key购买 nike

编译 TCL/Tk 时 manually from sources或者只是 install it from 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 会在相对于(DLL 的)目录 ../lib/tk8.5 和 ../lib 中搜索所有 TCL/TK 文件/tcl8.5。这使得在不必让最终用户安装 TCL 和 TK 的情况下分发您的应用变得相当困难。

我想分发我的 C++ 应用。

我使用 CPPTK默认 GUI 布局。

我想让最终用户不需要安装 TCL 和 TK。我想为他们提供包含 TK 和 TCL .TCL 源文件的文件夹,这些文件将位于与我的应用相关的某个目录中,例如 extras/TCLextras/传统知识。如何告诉 TK 和 TCL DLL 源文件文件夹在哪里?这样做的 TK 和 TCL API 函数名称是什么?是否有任何特殊的 cpptk 函数?

更新所以我尝试了 Donal Fellows answer具有下一个文件夹结构。

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 行失败

顺便说一句:我用了 this html\js app to get char string.

最佳答案

如果您有一个包含您的二进制文件的目录,并且您想要找到相对于它的那些 Tcl 文件,如下所示:

yourapp1.0/  +- yourapp.exe  +- extras/       +- tcl/            +- foo.tcl            +- bar.tcl       +- tk/            +- grill.tk

Then you can write Tcl code to find those scripts. That code would be like this:

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 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 源代码并进行猜测。 买者自负

关于c++ - 如何告诉TCL和TK在本地搜索默认 `.tcl`语言文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6553232/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com