如何解决SCons构建Godot扩展时‘文件已存在无法创建’错误?
构建Godot C++扩展时SCons报错“无法创建已存在的文件”
我在用C++开发Godot扩展,godot-cpp库编译正常,但执行构建命令时遇到报错,提示“Cannot create a file when that file already exists”。尝试删除godot-cpp绑定并重新编译,问题依然存在。
初始错误日志
PS C:\Users\****\OneDrive\Skrivebord\gdDynamicMesh\godot-cpp> scons target=template_debug platform=windows scons: Reading SConscript files ... Auto-detected 32 CPU cores available for build parallelism. Using 31 cores by default. You can override it with the -j argument. Building for architecture x86_64 on platform windows scons: done reading SConscript files. scons: Building targets ... Generating gen\include\godot_cpp\core\ext_wrappers.gen.inc ... scons: *** [gen\include\godot_cpp\core\ext_wrappers.gen.inc] C:\Users\\OneDrive\Skrivebord\gdDynamicMesh\godot-cpp\gen: Cannot create a file when that file already exists scons: building terminated because of errors.
带栈追踪的错误日志
PS C:\Users\****\OneDrive\Skrivebord\gdDynamicMesh\godot-cpp> scons target=template_debug platform=windows --debug=stacktrace scons: Reading SConscript files ... Auto-detected 32 CPU cores available for build parallelism. Using 31 cores by default. You can override it with the -j argument. Building for architecture x86_64 on platform windows scons: done reading SConscript files. scons: Building targets ... Generating gen\include\godot_cpp\core\ext_wrappers.gen.inc ... scons: *** [gen\include\godot_cpp\core\ext_wrappers.gen.inc] C:\Users\chris\OneDrive\Skrivebord\gdDynamicMesh\godot-cpp\gen: En fil, som allerede findes, kan ikke oprettes scons: internal stack trace: File "C:\Users\****\AppData\Roaming\Python\Python313\site-packages\SCons\Taskmaster\Job.py", line 737, in _work task.execute() ~~~~~~~~~~~~^^ File "C:\Users\****\AppData\Roaming\Python\Python313\site-packages\SCons\Script\Main.py", line 223, in execute SCons.Taskmaster.OutOfDateTask.execute(self) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "C:\Users\****\AppData\Roaming\Python\Python313\site-packages\SCons\Taskmaster\__init__.py", line 246, in execute self.targets[0].build() ~~~~~~~~~~~~~~~~~~~~~^^ File "C:\Users\****\AppData\Roaming\Python\Python313\site-packages\SCons\Node\__init__.py", line 757, in build self.get_executor()(self, **kw) ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^ File "C:\Users\****\AppData\Roaming\Python\Python313\site-packages\SCons\Executor.py", line 386, in __call__ return _do_execute_map[self._do_execute](self, target, kw) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^ File "C:\Users\****\AppData\Roaming\Python\Python313\site-packages\SCons\Executor.py", line 122, in execute_action_list raise status # TODO pylint E0702: raising int not allowed ^^^^^^^^^^^^ scons: building terminated because of errors.
解决办法
- 彻底清理生成目录:直接删除godot-cpp下的
gen文件夹,再重新执行构建命令,避免残留文件冲突。 - 移出OneDrive目录:项目存放在OneDrive下可能因为同步锁定文件,导致SCons无法操作。把项目移到本地非同步目录(如
C:\Projects),或暂时关闭OneDrive对该文件夹的同步。 - 限制并行线程数:高并行构建可能引发文件竞争,执行命令时加上
-j参数指定线程数,比如:scons target=template_debug platform=windows -j 4 - 匹配SCons版本:确认SCons版本与godot-cpp要求兼容,卸载当前版本后安装指定版本(比如Godot 4.x对应SCons 4.5.x)。
- 手动创建目录结构:如果
gen\include\godot_cpp\core目录不存在,手动创建完整路径后再执行构建。
内容的提问来源于stack exchange,提问作者Sekaus
相关产品推荐
相关产品推荐

