Native C++ linker issue due to cmd.exe /C ""clang_cmake_args"" -> [ERROR] [...] The command line is too long.

44 views
Skip to first unread message

Rain Ger

unread,
Jan 23, 2018, 1:31:16 PM1/23/18
to android-ndk
Hi,

I am fairly new to Android development and I am struggling with a C++ linking issue. This is on Windows 10, where we use JNI to call a C++ class that in turn executes the google unit tests that we have for all our C++ code. Since our application is written in C++ and needs to work on both Windows and Android, we want to run the same native unit tests on both platforms. The shared objects are compiled using ndk-build and we are linking to said .so files using CMake, to be able to run all our unit tests.

By default Android Studio uses `cmd.exe /C ""list-of-all-arguments""` on Windows to link the shared objects and since there are quite a few, it blows up past the 8192 cmd.exe character limit. 

It seems there is a way to tell cmake to use a "response file" but Android Studio *still* runs "cmd /c list-of-all-arguments" so it fails the same way (or I haven't correctly updated the CMakeLists.txt or build.gradle files).

There are apparently ways to configure the `executable` and `args` parameters in build.gradle but I can't find any useful documentation describing this, so I am stuck yet again.

How do I get around the issue of the "list-of-all-arguments" imposed by Android Studio (by insisting on using "cmd.exe /C list-of-all-arguments")?

A quick glance shows that there are 44 .so objects that I need to link but because of the file locations, including the full path to the cmake.exe and clang++.exe executables (six references to the full path where ndk-bundle is located, each is at least 80 characters long so that's around 500 characters right there), the argument passed to "cmd.exe /C" is longer than 8192 characters.

I would really appreciate it if someone could help me get around this Windows-specific limitation.

Thank you,
R.G.

Rain Ger

unread,
Mar 23, 2018, 2:19:43 PM3/23/18
to android-ndk
D'UH!

Our problem was with the CMakeLists.txt files: We would copy all compiled shared objects to our "android" working directory, and each copy instruction was easily 400 characters long due to the use of full paths for the command, source, and destination.

By removing the custom copy commands in our CMakeLists.txt files and updating the build.gradle files to use sourceSets.main.jniLibs.srcDirs "/path/to/our/SO/files", the command line length was no longer an issue and the build system was able to find the shared objects. The srcDirs path we originally used was changed at one point and no longer valid, and we apparently updated the CMakeLists.txt files rather than fixing the srcDirs path.

sourceSets {
    main {
        jniLibs.srcDirs = ['libs']
    }
}

This doesn't resolve my initial question but it seems unlikely that there is a way to get around the 8192 character limit.
Reply all
Reply to author
Forward
0 new messages