RT-Thread / RT-Thread/rt-thread
scons Windows 平台编译报错(文件路径太长)规避办法
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 12.2k
- Forks
- 5.4k
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 40
Description
报错内容:
arm-none-eabi-g++: fatal error: cannot execute'c:/programfiles/env-windows-v1.3.2/tools/gnu_gcc/armgcc/mingw/bin/../lib/gcc/arm-none-eabi/10.3.1/collect2.exe: CreateProcess: No such file or directory

原因:
链接时参数(.o文件集合)长度超过windows限制的最大长度。CreateProcess WINAPI函数,它接受参数的最大长度是32767个字符。因为代码保存的路径比较深,编译的文件又比较多,导致在链接的时候长度超过了32767

解决办法
- 缩短文件路径
- 分模块编译
第一种,比较简单的做法就是给代码库换个存储位置,但这样做不太优雅,而且别人也很容易再遇到相同问题。所以我使用了另一种方式,把编译生成的.o文件统一放到一个文件夹下面来缩短路径。这个方式需要更改的地方并不多,具体如下:

通过下图可以看出,编译时的路径,明显缩短了很多,而且不再受代码库存储位置的影响。当然这种方式如果文件很多,还是会出现问题,目前对于我的应用(编译二三百个文件)来说是够了。如果这个方法不能满足您的需求,那有可能得用第二种方法了。

很抱歉,第二种方法我还没搞明白该怎么弄,,,
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is identified in the issue. Start by reproducing the Windows SCons build with a deeply nested repository path and inspect how object-file paths are assembled for linking; done means the build avoids the reported CreateProcess length failure without requiring users to relocate the repository.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- build-system, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100