未定义的引用将Android中的预构建共享库与NDK链接

时间:2011-04-19 13:48:04

标签: android linker shared-libraries android-ndk

我有一个名为“tshark.so”的预构建共享库,每当我构建另一个共享库(libwireshark_helper.so)时,我都会尝试链接。 libtshark.so在$(LOCAL_PATH)中。这是我的Android.mk

LOCAL_PATH:= $(call my-dir)                                                                                                                                                                                                                                                        
include $(CLEAR_VARS)                                                                                                                                                                                                                                                              
NDK_MODULE_PATH := $(LOCAL_PATH)                                                                                                                                                                                                                                                   
LOCAL_SRC_FILES:= wireshark_helper.c                                                                                                                                                                                                                                
LOCAL_MODULE := libwireshark_helper                                                                                                                                                                                                                                                
LOCAL_PREBUILT_LIBS := libtshark.so                                                                                                                                                                                                                                                
LOCAL_C_INCLUDES += jni/libusb-compat/libusb jni/wispy jni/libpcap jni/libwireshark jni/libglib jni/libglib/glib jni/libglib/android jni/libwireshark/epan jni/libwireshark/epan/dissectors                                                                                        
LOCAL_SHARED_LIBRARIES := libc libusb libusb-compat libwispy libpcap libglib-2.0 libgmodule-2.0 libnl libtshark                                                                                                                                                                    
LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -L$(LOCAL_PATH) -llog -ltshark -lgcc -lz                                                                                                                                                                                                      
include $(BUILD_SHARED_LIBRARY)

例如,'tshark'库包含方法'tshark_log_handler',如下所示:

$ arm-eabi-nm libtshark.so | grep tshark_log_handler
005d298c t tshark_log_handler

然而,当我尝试构建时,我收到错误:

SharedLibrary  : libwireshark_helper.so
/Users/gnychis/Documents/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-g++ -Wl,-soname,libwireshark_helper.so -shared --sysroot=/Users/gnychis/Documents/android-ndk-r5b/platforms/android-9/arch-arm   /Users/gnychis/Documents/workspace/CoexiSyst/obj/local/armeabi/objs-debug/wireshark_helper/wireshark_helper.o    /Users/gnychis/Documents/workspace/CoexiSyst/obj/local/armeabi/libusb.so /Users/gnychis/Documents/workspace/CoexiSyst/obj/local/armeabi/libusb-compat.so /Users/gnychis/Documents/workspace/CoexiSyst/obj/local/armeabi/libwispy.so /Users/gnychis/Documents/workspace/CoexiSyst/obj/local/armeabi/libpcap.so /Users/gnychis/Documents/workspace/CoexiSyst/obj/local/armeabi/libglib-2.0.so /Users/gnychis/Documents/workspace/CoexiSyst/obj/local/armeabi/libgmodule-2.0.so /Users/gnychis/Documents/workspace/CoexiSyst/obj/local/armeabi/libnl.so /Users/gnychis/Documents/android-ndk-r5b/platforms/android-9/arch-arm/usr/lib/libc.so /Users/gnychis/Documents/android-ndk-r5b/platforms/android-9/arch-arm/usr/lib/libstdc++.so /Users/gnychis/Documents/android-ndk-r5b/platforms/android-9/arch-arm/usr/lib/libm.so   -Wl,--no-undefined -Wl,-z,noexecstack -L/Users/gnychis/Documents/android-ndk-r5b/platforms/android-9/arch-arm/usr/lib -L/Users/gnychis/Documents/android-ndk-r5b/platforms/android-9/arch-arm/usr/lib -L/Users/gnychis/Documents/workspace/CoexiSyst/jni/libwireshark -llog -ltshark -lgcc -lz -Wl,-rpath-link=/Users/gnychis/Documents/android-ndk-r5b/platforms/android-9/arch-arm/usr/lib -lsupc++ -o /Users/gnychis/Documents/workspace/CoexiSyst/obj/local/armeabi/libwireshark_helper.so
/Users/gnychis/Documents/workspace/CoexiSyst/obj/local/armeabi/objs-debug/wireshark_helper/wireshark_helper.o: In function `Java_com_gnychis_coexisyst_CoexiSyst_wiresharkHello':
/Users/gnychis/Documents/workspace/CoexiSyst/jni/libwireshark/wireshark_helper.c:124: undefined reference to `tshark_log_handler'

为什么我要获得未定义的引用?它在我的共享库中,并且在我的gcc命令中有一个“-ltshark”。我没有得到它找不到这个库的错误。

1 个答案:

答案 0 :(得分:4)

nm中的符号类型“t”表示符号位于库中,但不是全局符号。全局函数显示为符号类型“T”。换句话说,该函数是使用“static”关键字声明的,您不能在代码中使用它。