如何从.o文件中删除未定义的符号

时间:2016-09-21 08:07:49

标签: c shared-libraries undefined-reference

我必须使用另一个静态库构建一个共享库。在该静态库中,有一些函数调用在nm output中未定义。我想通过获取目标文件来删除这些符号。我无法删除整个目标文件,因为它的某些部分被使用。有没有办法做到这一点。

nm output

request.o:
         U CLR_SECURE_MEM_START_ADDR   //want to remove
         U clrSMEMAlloc                //want to remove
         U clrSMEMCopy                 //want to remove
         U clrSMEMFree                 //want to remove
         U clrSMEMSet                  //want to remove
00000000 T copyBuffer
00000000 T copyParameter
00000000 T copyRequest
00000000 T freeParameter
00000000 T freeRequest
00000000 T getLinkFromRequest
         U _gp_disp
00000000 T initializeRequest
00000000 T initializeRequestQueue
         U isClrSMEMBuffer
00000000 T isParamInSharedMem
00000000 T isRequestInSharedMem
00000004 b RequestQueue
00000000 b RequestQueueHead
         U strlen
00000000 T verifyParameter             ////want to keep
00000000 T verifyParameterType
00000000 T verifyParameterTypes
00000000 T verifyRequestParameters

我没有这个目标文件的来源,所以我不知道我要删除的函数的原型。如果我有源,我可以编写虚拟定义。 P.S 我的图书馆坏了。这就是为什么我有未定义的引用。

1 个答案:

答案 0 :(得分:1)

根据Michael Walz的评论,我并不需要删除.o文件。我只需要创建一个文件depend.c。为那些未定义的函数定义。然后建立它

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := libdepend
LOCAL_SRC_FILES := src/depend.cpp

LOCAL_CFLAGS := -DCLR_INTERAPTIV_I7 -DCLR_INTERAPTIV -v
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../RIP/include/ $(LOCAL_PATH)/../../../hardware/libhardware/include/hardware $(LOCAL_PATH)/../../../hardware/libhardware/include $(LOCAL_PATH)/src $(LOCAL_PATH)/../../RIP/inc

LOCAL_SHARED_LIBRARIES = libsmem.sastra

LOCAL_LDFLAGS := -v -L$(ANDROID_PRODUCT_OUT)/system/lib -lsmem.$(TARGET_BOARD_PLATFORM) -L$(LOCAL_PATH)/../../RIP/library -llibrary -llog -lcutils -lipc.$(TARGET_BOARD_PLATFORM)

#this option will build executables instead of building library for android application.
include $(BUILD_EXECUTABLE)

从out文件夹中获取此文件的.o。 从图书馆获取所有.os。 现在

 ar -x library.a   //get original object files

使用depend.o通过此命令打包此库中的所有.os

 ar r library.a *.o  //put depend.o with other object files 

现在构建共享库

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := libRip
LOCAL_SRC_FILES := src/Rip_api.cpp src/Rip_crypto.cpp

LOCAL_CFLAGS := -DCLR_INTERAPTIV_I7 -DCLR_INTERAPTIV -v

#only include corelockr and rip headers
LOCAL_C_INCLUDES := $(LOCAL_PATH)/inc/ $(LOCAL_PATH)/include/  $(LOCAL_PATH)/../../hardware/libhardware/include/hardware/

LOCAL_LDLIBS := -llog -L$(LOCAL_PATH)/library -llibrary
LOCAL_SHARED_LIBRARIES = libsmem.sastra
#test seqr library
#LOCAL_LDFLAGS := -v -L$(LOCAL_PATH)/library -llibrary

#this option will build static library
include $(BUILD_SHARED_LIBRARY)

现在共享库应该没有任何问题。

*******它是一种解决方法,而不是一个真正的解决方案。*******