Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot read/parse command line arguments in Android

Status
Not open for further replies.

MAKNIGHT71

IS-IT--Management
Sep 25, 2003
67
US
I am developing a command line app (to be run from the shell provided by the Android Debug Bridge [ADB] tool), but the command line arguments are not available via argc/argv in main(int argc, char *argv[]), and a call to basename(argv[0]) simply returns ".". Other than that the application runs fine.

Ideas? Suggestions?

TIA

My Makefile is as follows:

#
# Makefile command line application on Android

APP := appname
ROOT := /home/user/Android
NDK_PLATFORM_VER := 8
INSTALL_DIR := /data/local

# Set the tool directories
ANDROID_NDK_ROOT := $(ROOT)/android-ndk-r4b
ANDROID_NDK_HOST := linux-x86
ANDROID_SDK_ROOT := $(ROOT)/android-sdk-linux_86
PREBUILD := $(ANDROID_NDK_ROOT)/build/prebuilt/$(ANDROID_NDK_HOST)/arm-eabi-4.4.0
BIN := $(PREBUILD)/bin

# Setup the tools
CPP := $(BIN)/arm-eabi-g++
CC := $(BIN)/arm-eabi-gcc
GDB_CLIENT := $(BIN)/arm-eabi-gdb

# Set the build flags
CFLAGS := -I$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/include
CFLAGS += -DDEBUG -DANDROID
LDFLAGS := -Wl,--entry=main,-rpath-link=$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/lib,-dynamic-linker=/system/bin/linker -L$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/lib
LDFLAGS += $(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/lib/crtbegin_dynamic.o -nostdlib -lc

all: $(APP)

OBJS += $(APP).o

$(APP): $(OBJS)
$(CPP) $(LDFLAGS) -o $@ $^

%.o: %.c
$(CC) -c $(INCLUDE) $(CFLAGS) $< -o $@

install: $(APP)
$(ANDROID_SDK_ROOT)/tools/adb push $(APP) $(INSTALL_DIR)/$(APP)
$(ANDROID_SDK_ROOT)/tools/adb shell chmod 777 $(INSTALL_DIR)/$(APP)

shell:
$(ANDROID_SDK_ROOT)/tools/adb shell

run:
$(ANDROID_SDK_ROOT)/tools/adb shell $(INSTALL_DIR)/$(APP)

debug:
$(GDB_CLIENT) $(APP)

clean:
@rm -f $(APP).o $(APP)
 
Fixed this myself following some more mucking about (funny how I fixed this right after posting after I have fought it for several days now). With crtbegin_dynamic included, you mustn't specify an entry point in your LDFLAGS.

New Makefile:

#
# Makefile command line application on Android

APP := appname
ROOT := /home/user/Android
NDK_PLATFORM_VER := 8
INSTALL_DIR := /data/local

# Set the tool directories
ANDROID_NDK_ROOT := $(ROOT)/android-ndk-r4b
ANDROID_NDK_HOST := linux-x86
ANDROID_SDK_ROOT := $(ROOT)/android-sdk-linux_86
PREBUILD := $(ANDROID_NDK_ROOT)/build/prebuilt/$(ANDROID_NDK_HOST)/arm-eabi-4.4.0
BIN := $(PREBUILD)/bin

# Setup the tools
CPP := $(BIN)/arm-eabi-g++
CC := $(BIN)/arm-eabi-gcc
GDB_CLIENT := $(BIN)/arm-eabi-gdb

# Set the build flags
CFLAGS := -I$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/include
CFLAGS += -DDEBUG -DANDROID
LDFLAGS := -Wl,-rpath-link=$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/lib,-dynamic-linker=/system/bin/linker -L$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/lib
LDFLAGS += $(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/lib/crtbegin_dynamic.o -nostdlib -lc

all: $(APP)

OBJS += $(APP).o

$(APP): $(OBJS)
$(CPP) $(LDFLAGS) -o $@ $^

%.o: %.c
$(CC) -c $(INCLUDE) $(CFLAGS) $< -o $@

install: $(APP)
$(ANDROID_SDK_ROOT)/tools/adb push $(APP) $(INSTALL_DIR)/$(APP)
$(ANDROID_SDK_ROOT)/tools/adb shell chmod 777 $(INSTALL_DIR)/$(APP)

shell:
$(ANDROID_SDK_ROOT)/tools/adb shell

run:
$(ANDROID_SDK_ROOT)/tools/adb shell $(INSTALL_DIR)/$(APP)

debug:
$(GDB_CLIENT) $(APP)

clean:
@rm -f $(APP).o $(APP)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top