当您从源代码手动编译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(目录的所有TCL/TK文件/lib/tk8.5和/lib/tcl8.5.这使得分发应用程序变得非常困难,而不必让最终用户安装TCL和TK.
我想分发我的C++应用程序。
我使用CPPTK作为默认GUI布局。
我想让它成为可能,这样最终用户就不需要安装TCL和TK。我想为他们提供包含TK和TCL .TCL
源文件的文件夹,这些文件将位于与我的应用程序相关的某个目录中,如extras/TCL
和extras/TK
。如何告诉TK和TCL DLL源文件夹在哪里?TK和TCL API函数的名称是什么?有什么特殊的cpptk函数吗?
更新所以我试着用下一个文件夹结构来回答多纳尔·费罗斯的问题。
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]]/extrasn"
"# Now use it to load some code...n"
"source $extrasDir/tcl/init.tcln"
"# Another way to load code, using all *.tk files from a directory:n"
"foreach tkFile [glob -nocomplain -directory $extrasDir/tk *.tk] {n"
" source $tkFilen"
"}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行失败
BTW:我用这个html\js应用程序来获取字符串。
如果你有一个包含二进制文件的目录,并且你想定位那些与之相关的Tcl文件,比如:
您的应用程序1.0/+-yourapp.exe+-额外费用/+-tcl/+-foo.tcl+-bar.tcl+-tk/+-格栅.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]
(尽管有一些注意事项(。
[EDIT]:要使该代码与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源代码并进行猜测洞穴清空。