Discussion:
Native C++ linker issue due to cmd.exe /C ""clang_cmake_args"" -> [ERROR] [...] The command line is too long.
Rain Ger
2018-01-23 16:37:29 UTC
Permalink
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.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/084f391a-52c3-4e7b-a61c-68eeafdd2072%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Rain Ger
2018-03-23 18:19:43 UTC
Permalink
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.
Post by Rain Ger
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.
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+***@googlegroups.com.
To post to this group, send email to android-***@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/dbd1d725-ed1c-4751-936a-91903393d5c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...