Command line length limitation

845 views
Skip to first unread message

VOLKER

unread,
Nov 23, 2011, 4:06:33 AM11/23/11
to android-ndk
Hi all,

although NDK r7 has brought us some reduction of the command line
length, we're still facing it with our current build setup. One way
would be to split the project into several static libraries, but our
cross-platform project generator toolchain we're using would be much
more complicated and debugging probably too. I wonder why the NDK does
not create a text file with the object file names and use this with
the @file option of g++. This way the 32k command line length
limitation under windows with the CreateProcess call of make(?) would
not be a limit to us and I guess many others. I tried it by copying
the arguments from the output window into a text file and a batch file
and it seem to work flawlessly but unfortunately I'm not familiar with
GNU Make so that I would be able to change the NDK toolchain to create
such a separate text file containing the $(PRIVATE_OBJECTS) (?) and
add this file using the @ option of g++.

Can anybody help me out, or even better can the NDK r8 may change this
to the default toolchain behaviour?

David Turner

unread,
Nov 23, 2011, 5:55:12 AM11/23/11
to andro...@googlegroups.com
Hello Volker,

That sounds a very reasonable feature enhancement to add to b.android.com.
I think it is something that could come with a future NDK release, since I'm interested in ways to improve the build system for large/complex projects.

Regards

- David
 

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


VOLKER

unread,
Nov 23, 2011, 12:58:51 PM11/23/11
to android-ndk
I puzzled a bit with the make files and one solution that currently
fits my needs is to change the following two files:

ndk/build/core/build-binary.mk
toolchains/arm-linux-androideabi-4.4.3/setup.mk

--- android-ndk-r7/build/core/build-binary_original.mk Mi Nov 23
18:52:03 2011
+++ android-ndk-r7/build/core/build-binary.mk Mi Nov 23 11:55:16 2011
@@ -304,13 +304,21 @@
ALL_STATIC_LIBRARIES += $(LOCAL_BUILT_MODULE)
endif

+# $1 script, $2 filespec
+define WRITE_CMD
+@ $(HOST_ECHO) -n "$(2) " >> $(1)
+
+endef # keep blank line above
+
#
# If this is a shared library module
#
ifeq ($(call module-get-class,$(LOCAL_MODULE)),SHARED_LIBRARY)
$(LOCAL_BUILT_MODULE): $(LOCAL_OBJECTS)
@ $(call host-mkdir,$(dir $@))
- @ $(HOST_ECHO) "SharedLibrary : $(PRIVATE_NAME)"
+ @ $(HOST_ECHO) "SharedLibrary : $(PRIVATE_NAME)"
+ $(hide) $(HOST_ECHO) -n > objects.txt
+ $(hide) $(foreach ofile,$(PRIVATE_OBJECTS), $(call
WRITE_CMD,objects.txt,$(ofile)))
$(hide) $(cmd-build-shared-library)

ALL_SHARED_LIBRARIES += $(LOCAL_BUILT_MODULE)


--- android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/
setup_original.mk Mi Nov 23 18:51:49 2011
+++ android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/setup.mk Mi
Nov 23 10:34:53 2011
@@ -122,7 +122,7 @@
-Wl,-soname,$(notdir $@) \
-shared \
--sysroot=$(call host-path,$(PRIVATE_SYSROOT)) \
- $(call host-path, $(PRIVATE_OBJECTS)) \
+ $(call host-path, @objects.txt) \
$(call link-whole-archives,$(PRIVATE_WHOLE_STATIC_LIBRARIES)) \
$(call host-path,\
$(PRIVATE_STATIC_LIBRARIES) \


It does not include all the other build targets and is slowing down
the build process a bit because of the many calls to WRITE_CMD
but it works.

Would be nice if a clean solution may find its way to the next NDK
release.


On 23 Nov., 11:55, David Turner <di...@android.com> wrote:
> Hello Volker,
>

dnick

unread,
Nov 23, 2011, 1:20:38 PM11/23/11
to android-ndk
If you don't want to change NDK's setup.mk, you can just override
linker command in your Android.mk file.
My android project generator before 'include $(BUILD_SHARED_LIBRARY)'
string inserts following code:
---- Android.mk ----
......
################################################################
#following code is modified copy of `cmd-build-shared-library` from
%NDK%/toolchains/arm-linux-androideabi-4.4.3/setup.mk
# it is modified to use separate .linkargs file for linker, because
otherwise 'Argument list too long' error occurs.
# /dnick
define cmd-build-shared-library
$(eval linkargs := $(call host-path,$@.linkargs))
@ echo 'Link arguments : ' $(linkargs)
$(hide) echo \

-Wl,-soname,$(notdir $@) \
-shared \
--sysroot=$(call host-path,$(PRIVATE_SYSROOT)) \
> $(linkargs)

$(hide) $(foreach object, $(call host-path, $(PRIVATE_OBJECTS)), echo
'$(object)' >> $(linkargs); )

$(hide) echo \


$(call link-whole-archives,$(PRIVATE_WHOLE_STATIC_LIBRARIES)) \
$(call host-path,\
$(PRIVATE_STATIC_LIBRARIES) \

$(PRIVATE_LIBGCC) \
$(PRIVATE_SHARED_LIBRARIES)) \
$(PRIVATE_LDFLAGS) \
$(PRIVATE_LDLIBS) \
-o $(call host-path,$@) \
>> $(linkargs)

$(hide) $(PRIVATE_CXX) @$(linkargs)
endef
################################################################

P.S.
you can use this way with r6 too, but be careful to not miss -lsupc++
linker option (it gone with r7)

Reply all
Reply to author
Forward
0 new messages