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?

preetam
  • 1,451
  • 1
  • 17
  • 43
  • I think you need ar to bundle dev_access.o into a lib dev_access.a – Jiminion May 14 '14 at 04:43
  • ar libdev_access.a dev_access.o – Jiminion May 14 '14 at 04: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. – preetam May 14 '14 at 05:13
  • This error seems to be coming from the include of stdio.h itself. – preetam May 14 '14 at 05:14
  • You need to find machine/... and put it in your include path. – Jiminion May 14 '14 at 05:50
  • 1
    You should be using these include paths: libc/arch-$ARCH/include libc/include libc/kernel/common libc/kernel/arch-$ARCH – Jiminion May 14 '14 at 06:08
  • Including the machine folder is creating lots of redefinition errors among the include files. – preetam May 14 '14 at 06:18
  • I managed to get a compiles libc.a. Can you tell me how to statically link with it. please give me make commands for it. – preetam May 14 '14 at 06:20
  • Thanks for the list of files to include. As it turns out, I had left out the common and kernel/arch-arm. As I have cross compiled for arm, the 'ar' command is not working. Gives out 'ar: invalid option --e' But I actually used the same command without any arguments. Did not pass -e at all. – preetam May 14 '14 at 06:44
  • @Jim Thanks for all the help. I finally got it. – preetam May 14 '14 at 07:03
  • Good job! Glad you got it. – Jiminion May 14 '14 at 07:34

1 Answers1

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>
preetam
  • 1,451
  • 1
  • 17
  • 43
Jiminion
  • 5,080
  • 1
  • 31
  • 54