开发者

Problem linking to <sys/msg.h> with Android.mk

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/ms开发者_如何学Pythong.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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜