1

I am writing a C program for use on the android command line. I haven't had any issues compiling until I started using message queues and including linux/msg.h (or sys/msg.h). I am not sure what the right library to link to is or even how to do it with Android.mk. I have been through as many questions as possible and no answer has seemed to work.

The exact errors that I'm getting:

  • sys/msg.h: No such file or direcory
  • implicit declaration of function 'msgget'
  • implicit declaration of function 'msgsnd'
  • implicit declaration of function 'msgrcv'
  • implicit declaration of function 'msgctl'

Here is my Android.mk file:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_SRC_FILES := appX.c 
LOCAL_MODULE := appX
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_LIBRARIES := libc
LOCAL_C_INCLUDES := $(LOCAL_PATH)
include $(BUILD_EXECUTABLE)

I really appreciate any help.

peter
  • 6,067
  • 2
  • 33
  • 44
  • You haven't mentioned why you want to use Linux message queues. There might be a more Android-y way to go about whatever it is you want to do. Can you supply any more details about your application? – Ian Ni-Lewis Aug 16 '11 at 22:16
  • I really just needed IPC. However, I realised that I could get away with multithreading instead of multiprocessing. – peter Aug 19 '11 at 16:19

1 Answers1

3

The NDK headers in $(NDK_ROOT)/platforms/android-[X]/usr/include are the only headers supported by the NDK. If you use other Android or Linux headers, your app is likely to break in the future.

Why is this? Because most Android apps run in the Dalvik virtual machine and are insulated from the system by layers of Java framework classes, the Android authors can afford to be fairly cavalier about the underlying Linux system. They are free to change headers and libraries as often as they want, as long as they keep the Java layer compatible. The same goes for the NDK: as long as they don't break the very limited set of headers and libraries that the NDK provides, they can change whatever they want to change under the hood.

So by design the NDK make system does not make it easy to link to anything but the NDK libraries. If it made it easy to talk to random Linux headers, it would defeat the purpose of the NDK.

Ian Ni-Lewis
  • 2,377
  • 20
  • 20