2013年9月24日星期二

android NDK development, encounter undefined reference to

I now have an android project, there is a des.h header files and des.cpp, NZEncryption.c two documents, some functions are declared in the header file des.h in des.cpp achieve . Then NZEncryption.c use ,

project directory structure


declared in the header file NZEncryption.c
#include <string.h>
#include <jni.h>
#include "des.h"


Then Android.mk in writing as follows:
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_C_INCLUDES := $(LOCAL_PATH)/include
LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog

LOCAL_MODULE    := NewZone01
LOCAL_SRC_FILES := NZEncryption.c\
                   des.cpp

include $(BUILD_SHARED_LIBRARY)


but using Cygwin build . so file , the prompt : undefined reference to "des_encrypt"
When des_encrypt declared in des.h , implemented in des.cpp
do not know how , how can correctly generate the


------ Solution ------------------------------------ --------
C defined function calls inside the CPP , you need to add anything inside
extern "C" {
...
}
------ For reference only --------------------------------- ------
If android.mk to add this one : LOCAL_ALLOW_UNDEFINED_SYMBOLS: = true
is able to compile, but running error.
should be a function of not being properly compiled in.
------ For reference only -------------------------------------- -
your project inside another cpp, c ??
------ For reference only ---------------------- -----------------
Yes , NDK to the sample code in there ,
project where you can have c, cpp, there

------ For reference only ----- ----------------------------------


positive solution, thank you very much !

没有评论:

发表评论