3

I just wrote a small c file and its header file. dev_access.c and dev_access.h

I want to link it to the bionic library in android and create a statically/dynamically linked archive file.

My files are in /home/preetam/mydev/ The android sources are in /home/preetam/android_source

The following is my current makefile

CROSS           := /home/preetam/bin/CodeSourcery/arm2010/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi
CC              := $(CROSS)-gcc
INC_DIR         := /home/preetam/android_source/bionic/libc
CFLAGS          := -Wall -c -I$(INC_DIR)/include

android_hal: dev_access.o
        ${CC} ${CFLAGS} dev_access.c -o dev_access.a

clean:
        rm -f *.o dev_access.a

I am not sure whats going wrong but header files are not linking and some missing and redefinition errors are coming up. The following is the Console output:

/home/preetam/bin/CodeSourcery/arm2010/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-gcc -c -Wall -I/home/preetam/android_source/bionic/libc/include -static   -c -o dev_access.o dev_access.c
In file included from /home/preetam/android_source/bionic/libc/include/stdio.h:42,
                 from dev_access.c:1:
/home/preetam/android_source/bionic/libc/include/sys/_types.h:40: fatal error: machine/_types.h: No such file or directory
compilation terminated.
make: *** [dev_access.o] Error 1

First of all, Is my Makefile correct? Whats the proper way to link your programs with bionic libc ? How to make the final object an archive?

11
  • I think you need ar to bundle dev_access.o into a lib dev_access.a Commented May 14, 2014 at 4:43
  • ar libdev_access.a dev_access.o Commented May 14, 2014 at 4:47
  • I am not able to get make to compile. I am not sure what needs to be included. Also I am not sure if I need the compiled bionic or if the source will suffice. Commented May 14, 2014 at 5:13
  • This error seems to be coming from the include of stdio.h itself. Commented May 14, 2014 at 5:14
  • 1
    You should be using these include paths: libc/arch-$ARCH/include libc/include libc/kernel/common libc/kernel/arch-$ARCH Commented May 14, 2014 at 6:08

1 Answer 1

1

You should be using these include paths for bionic:

libc/arch-$ARCH/include 
libc/include 
libc/kernel/common 
libc/kernel/arch-$ARCH

ar might have some switches for it...

EDIT: The switch is cr

ar -crv <libname> <source_object>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.