Skip to main content
 首页 » 编程设计

python之如何使 cx_Freeze 将子模块编译成共享对象 (.so) 文件

2024年11月24日8fff_TT

背景

  • 我在一家公司工作,该公司正在编写代码来控制电视屏幕,播放通过互联网下载的广告。
  • 我的老板希望在我们将源代码提供给将要制造屏幕 Controller 计算机的工厂之前编译源代码,这样代码就不会轻易被复制/逆向工程。
  • 我的老板决定 .pyc files are too easy to reverse-engineer ,并且更愿意编译为二进制(?)文件,其中一种(?)似乎是 .so 文件。
  • 我现在正尝试使用 cx_Freeze 将我们所有的源代码转换为 .so 文件。

问题

当我运行 python setup.py build(具有 cx_Freeze 的命令“编译”我们的应用程序)时,似乎只有我指定为“主”文件的一个文件被转换为 .so 文件,而我们的源代码的其余部分被转换为 .pyc。我们希望我们的所有代码都是.so文件。

我尝试过的

  • 我已尝试浏览 cx_Freeze 文档,但看不出如何完成我们正在尝试做的事情。

请您参考如下方法:

这不可能。

我给 cx_Freeze 的创建者 (Anthony Tuininga) 发了邮件,这是他的回复:

cx_Freeze doesn't have that capability. It puts all of its compiled Python code (.pyc files) into a zip file. Technically, there is a way to do so, but cx_Freeze doesn't do so. Since it involves a C compiler its more complex and prone to error.