ndk-build: CreateProcess: make (e=87): 参数不正确

2022-01-10 00:00:00 windows android-ndk c++ createprocess

在 Windows 平台上使用 NDK 构建静态库时出现错误:

I get an error when build static lib with NDK on Windows platform:

process_begin: CreateProcess( "PATH"android-ndk-r8b	oolchainsarm-linux-androideabi-4.6prebuiltwindowsinarm-linux-androideabi-ar.exe, "some other commands" ) failed.
make (e=87): The parameter is incorrect.
make: *** [obj/local/armeabi-v7a/staticlib.a] Error 87
make: *** Waiting for unfinished jobs....

所有源文件构建成功,编写目标文件时出现此错误.

All source files build successfully, and this error occur when compose object files.

在 Ubuntu 中构建此项目时,我没有收到此错误,它仅在 Windows 上发生.

I don't get this error when build this project in Ubuntu, it occur only on Windows.

我想我找到了 问题:CreateProcess Win API 函数 lpCommandLine 的最大长度为 32,768 个字符.但就我而言,它超过 32,768 个字符.

I suppose I found the issue: second parameter of CreateProcess Win API function lpCommandLine has max length 32,768 characters. But in my case it is more than 32,768 characters.

我该如何解决这个问题?

How I can solve this issue?

推荐答案

也许在你的 Android.mk 中设置的 LOCAL_SHORT_COMMANDS 标志可以帮助你.它旨在克服 Windows 命令可以处理的字符数限制.

Maybe the LOCAL_SHORT_COMMANDS flag, to be set in your Android.mk, could help you. It is designed to overcome the limitations on the number of characters a Windows command can handle.

根据$(NDK文件夹)/docs/ANDROID-MK.html:

According to $(NDK folder)/docs/ANDROID-MK.html:

LOCAL_SHORT_COMMANDS

LOCAL_SHORT_COMMANDS

当您的模块有大量源和/或依赖的静态或共享库.这迫使构建系统以使用中间列表文件,并将其与使用 @$(listfile) 语法的库归档器或静态链接器.

Set this variable to 'true' when your module has a very high number of sources and/or dependent static or shared libraries. This forces the build system to use an intermediate list file, and use it with the library archiver or static linker with the @$(listfile) syntax.

这在 Windows 上很有用,命令行只接受最多 8191 个字符,对于复杂的项目.

This can be useful on Windows, where the command-line only accepts a maximum of 8191 characters, which can be too small for complex projects.

这也会影响单个源文件的编译,放置列表文件中的几乎所有编译器标志也是如此.

This also impacts the compilation of individual source files, placing nearly all compiler flags inside list files too.

请注意,true"以外的任何其他值都将恢复为默认值行为.您还可以在您的Application.mk 为您的所有模块强制执行此行为项目.

Note that any other value than 'true' will revert to the default behaviour. You can also define APP_SHORT_COMMANDS in your Application.mk to force this behaviour for all modules in your project.

注意:我们不建议默认启用此功能,因为它使构建变慢.

NOTE: We do not recommend enabling this feature by default, since it makes the build slower.

希望这会有所帮助!

相关文章