NDK中未定义的引用错误

时间:2015-11-11 19:30:10

标签: android c++ android-ndk undefined-reference

我正在尝试为Android编译unrar,但要获得一些undefined reference error。我被困在这里几天,但无法找到确切的问题。我尝试从现有的Android.mk撰写makefile

错误

jni/unrar/rar.cpp:104: error: undefined reference to 'CommandData::ParseCommandLine(bool, int, char**)'
jni/unrar/rar.cpp:107: error: undefined reference to 'CommandData::ReadConfig()'
jni/unrar/rar.cpp:108: error: undefined reference to 'CommandData::ParseEnvVar()'
jni/unrar/rar.cpp:110: error: undefined reference to 'CommandData::ParseCommandLine(bool, int, char**)'

Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
UNRAR_PATH := $(LOCAL_PATH)/unrar
LOCAL_MODULE    := unrar-jni

LOCAL_SRC_FILES := com_unrar_jni.cpp unrar/rar.cpp unrar/strlist.cpp unrar/strfn.cpp unrar/pathfn.cpp unrar/smallfn.cpp unrar/global.cpp unrar/file.cpp unrar/filefn.cpp unrar/filcreat.cpp \
    unrar/archive.cpp unrar/arcread.cpp unrar/unicode.cpp unrar/system.cpp unrar/isnt.cpp unrar/crypt.cpp unrar/crc.cpp unrar/rawread.cpp unrar/encname.cpp \
    unrar/resource.cpp unrar/match.cpp unrar/timefn.cpp unrar/rdwrfn.cpp unrar/consio.cpp unrar/options.cpp unrar/errhnd.cpp unrar/rarvm.cpp unrar/secpassword.cpp \
    unrar/rijndael.cpp unrar/getbits.cpp unrar/sha1.cpp unrar/sha256.cpp unrar/blake2s.cpp unrar/hash.cpp unrar/extinfo.cpp unrar/extract.cpp unrar/volume.cpp \
    unrar/list.cpp unrar/find.cpp unrar/unpack.cpp unrar/headers.cpp unrar/threadpool.cpp unrar/rs16.cpp unrar/cmddata.cpp unrar/ui.cpp \
    unrar/filestr.cpp unrar/recvol.cpp unrar/rs.cpp unrar/scantree.cpp unrar/qopen.cpp 

LOCAL_CFLAGS := -O2
LOCAL_CPPFLAGS := -fexceptions -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)

CommandDatacmddata.hpp中声明,并在cmddata.cpp文件中实施。 rar.hpp还包括cmddata.hpp但是为什么它抱怨函数未定义。

1 个答案:

答案 0 :(得分:1)

The source code you found is not complete, and does not carry official claims to compile, especially under Android. But the following steps can get you started:

  1. open new directory, open command line to that directory.
  2. mkdir jni
  3. put the Android.mk exactly as you have in your question to jni directory
  4. untar unrarsrc-5.3.6.tar.gz to jni/unrar
  5. add one line #88 in jni/unrar/rar.hpp: #undef _ANDROID
  6. create empty file jni/com_unrar_jni.cpp
  7. run ndk-build APP_CFLAGS="-Dgetpass\(a\)=a" APP_STL=stlport_static c++_static may work, too)