In Microsoft Visual Studio 2010, it is possible to create a Solution with multiple projects and set dependencies between projects. I'm trying to figure out if the same thing can be done using Eclipse via the NDK. More specifically, I want to know if it is possible to create C source files in an ordinary Android project that can reference C header files in an Android library project.
For example:
Android library project: Sockets
Ordinary Android project: Socket_Server
Sockets contains all the C header/source files that are needed to do socket I/O.
Socket_Server contains test code that makes calls to the functions that are defined in Sockets library project. This test code requires a header file that contains the function declaration of all API calls.
I already set the library dependencies between the projects via:
Properties > Android > Library > Add
In Socket_Server, there's a file called SocketTestServer.cpp. It contains test code, but makes API calls to the library project, Sockets, and does so by #include "Nv_Socket.h", which is not part of Socket_Server:
jni/SocketTestServer.cpp:1:23: fatal error: Nv_Socket.h: No such file or directory
compilation terminated.
I think I solved it. If you make a .so file, put it in your /jni folder and then reference it in your .mk file, you should have no problems compiling.
.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
# Turn on C++ Exception handling
LOCAL_CPP_FEATURES += exceptions
LOCAL_CPPFLAGS += -fexceptions
# Load LogCat utility
LOCAL_LDLIBS := -llog
# C flags
LOCAL_CFLAGS += -Wno-psabi -fpermissive
# Module name
LOCAL_MODULE := ServerSockets
# C Header includes
LOCAL_C_INCLUDES := $(LOCAL_PATH)
# Source files
LOCAL_SRC_FILES := libSockets.so
include $(PREBUILT_SHARED_LIBRARY)
See http://www.kandroid.org/ndk/docs/IMPORT-MODULE.html and http://www.kandroid.org/ndk/docs/PREBUILTS.html . The trick is not to have to copy the binary from one project to another! Also, using LOCAL_EXPORT_C_INCLUDES
you can guarantee that the up-to-date version is used with
#include "Nv_Socket.h"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.