Tuesday, September 17, 2013

[android help] Android NDK C++ Class undefined Reference


Android NDK C++ Class undefined Reference



You have multiple options here assuming that you have a first.cpp file that you implemented the Test class correctly. Without being able to see your Android.mk, I will go through all options:


Build First.cpp as a static or shared library and add this library to your module which compiles Second.cpp. Your Android.mk should look like:


LOCAL_PATH:= $(call my-dir)


include $(CLEAR_VARS)


LOCAL_MODULE := libtwolib-first


LOCAL_SRC_FILES := first.c


include $(BUILD_STATIC_LIBRARY)


If you would like First to be a shared library instead of a static library, change include $(BUILD_STATIC_LIBRARY) line to:



include $(BUILD_SHARED_LIBRARY)


Now, your second lib is compiled as follows:



include $(CLEAR_VARS)

LOCAL_MODULE := libtwolib-second
LOCAL_C_INCLUDES := path/to/first.h
LOCAL_C_INCLUDES += path/to/second.h
LOCAL_SRC_FILES := second.cpp

LOCAL_STATIC_LIBRARIES := libtwolib-first

include $(BUILD_SHARED_LIBRARY)


As a second solution, you can build first.cpp as a part of the second lib and this way you don't have to worry about linking against the first library. This is more like a design choice and how you would like to shape up your libraries:



include $(CLEAR_VARS
LOCAL_MODULE := libtwolib-second
include $(CLEAR_VARS)

LOCAL_MODULE := libtwolib-second
LOCAL_C_INCLUDES := path/to/first.h
LOCAL_C_INCLUDES += path/to/second.h
LOCAL_SRC_FILES := first.cpp
LOCAL_SRC_FILES += second.cpp

include $(BUILD_SHARED_LIBRARY)


Read more

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...