C++/Tk:我们能否创建一个可执行文件,无需最终用户安装任何特殊的 TcL 解释器即可运行?
将 C++/Tk 程序编译为可在其他用户计算机上运行的可执行文件的分步说明是什么,不需要最终用户安装任何其他软件,TCL tk 是否有完全静态的链接选项?
What are step by step instructions for compiling C++/Tk program into executable that would run on other users machines not requiring that end users to install any additional software, are there any entirely static link options for TCL tk?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Tcl 和 Tk 在静态构建时工作得很好;这是受支持的(但不是默认的)配置。只需获取源版本并使用
--disable-shared
配置它们即可确保它们为您构建正确类型的库。Colin 的回答链接到了您需要了解的有关从应用程序内部使用 Tcl 和 Tk 进行编码的大部分内容,例外,您还需要在调用其中任何一个之前调用
Tcl_FindExecutable
其他程序(我假设您没有调用Tcl_Main
或Tk_Main
,它们会为您执行此操作,但让您必须像这样工作分别为tclsh
和wish
)。这是确保 Tcl 库内部配置正确的必要调用,因为它处理初始化编码系统和其他类似的低级细节。如果您可以像使用 tclsh 或 Wish 一样构建您的程序,并且只需将您的 C++ 代码作为扩展包加载,我会敦促您构建您的代码 启用存根,然后将其全部打包为 starkit/starpack。特别是,starpack 是一个单文件可执行文件,它实际上是 Tcl 和 Tk 的独立二进制发行版以及压缩存档格式的应用程序代码。以这种方式分发应用程序确实相当不错,因为它可以避免将代码放在用户可能无意中破坏的地方,但它并不适合所有情况。 (有一些相关的解决方案也可以包括加密您的代码,但它们仅供商业用途。)
Tcl and Tk work just fine when built statically; this is a supported (but not default) configuration. Just get the source releases and configure them with
--disable-shared
to ensure that they build the right type of library for you.Colin's answer links to most of what you need to know about coding to use Tcl and Tk from inside your application, except you also need to call
Tcl_FindExecutable
before you call any of those other programs (I'm assuming you're not callingTcl_Main
orTk_Main
, which would do that for you but leave you bound to working liketclsh
andwish
respectively). That's a necessary call to ensure that the Tcl library is internally configured correctly, as it handles initializing the encoding system and other low-level details like that.If you can structure your program like it works with tclsh or wish and just loading your C++ code as an extension package, I would urge you to build your code stubs-enabled and then package it all as a starkit/starpack. In particular, a starpack is a single-file executable which is effectively a self-contained binary distribution of Tcl and Tk plus your application code in a compressed archive format. It's really rather nice to distribute apps this way as it avoids putting code where users can inadvertently break it, but it's not suitable for everything. (There are related solutions that can include encrypting your code too, but they're commercial-only.)
这是 Tcl 的最初用例,尽管现在不那么常见了。查看布伦特·韦尔奇 (Brent Welch) 书中的这一免费章节,了解不错但过时的介绍(或者购买他的书的第四版以获得更新版本)。另一个简短的摘要位于 Tcl wiki 上的将 Tcl/Tk 添加到 C 应用程序。
This was the original use-case for Tcl, though it's not so often done now. Take a look at this free chapter from Brent Welch's book for a good but dated introduction (or buy the 4th edition of his book for a more up-to-date version). Another short summary is at Adding Tcl/Tk to a C application on the Tcl wiki.