C++ AOSP-错误:未定义对<;的引用;函数名>;在构建期间

C++ AOSP-错误:未定义对<;的引用;函数名>;在构建期间,c++,linker,android-source,android.mk,C++,Linker,Android Source,Android.mk,我需要另一个眼睛好的人告诉我我做错了什么 我不得不在我的设备上升级U-boot引导程序,当然,我不得不让事情重新适应。但目前我无法像以前那样构建AOSP系统。我将从错误消息开始,并写下我的思考过程: target Symbolic: fw_printenv (out/target/product/board/symbols/system/bin/fw_printenv) target Strip: fw_printenv (out/target/product/board/obj/EXECUTA

我需要另一个眼睛好的人告诉我我做错了什么

我不得不在我的设备上升级U-boot引导程序,当然,我不得不让事情重新适应。但目前我无法像以前那样构建AOSP系统。我将从错误消息开始,并写下我的思考过程:

target Symbolic: fw_printenv (out/target/product/board/symbols/system/bin/fw_printenv)
target Strip: fw_printenv (out/target/product/board/obj/EXECUTABLES/fw_printenv_intermediates/fw_printenv)
Install: out/target/product/board/system/bin/fw_printenv
target Executable: test_executer (out/target/product/board/obj/EXECUTABLES/test_executer_intermediates/LINKED/test_executer)
external/utils/production/set_display_orientation.cpp:81: error: undefined reference to 'fw_printenv(int, char**, int, env_opts*)'
external/utils/production/set_display_orientation.cpp:57: error: undefined reference to 'fw_setenv(int, char**, env_opts*)'
external/utils/production/set_display_orientation.cpp:65: error: undefined reference to 'fw_printenv(int, char**, int, env_opts*)'
collect2: error: ld returned 1 exit status
这是一个链接器错误。我的代码找不到在另一个模块中定义的函数。让我们看看负责设置显示方向的Android.mk文件

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := test_executer
LOCAL_SRC_FILES := test_executer.cpp \
        TestSequences.cpp \
        buzzer_test.cpp \
        rtc_test.cpp \
        AudioTests.cpp \
        rs485_test.cpp \
        rs232.cpp \
        set_display_orientation.cpp \
        gpio.cpp \
        gpio_helper.c \
        ping.cpp \
        usb.cpp \
        mmc.cpp \
        display.cpp \
        touchscreen.cpp \
        productionSector.cpp \
        psoc_uart3.cpp \
        ../../tslib/tests/fbutils.c

LOCAL_MODULE_TAGS := optional

LOCAL_STATIC_LIBRARIES += libfw libeeprom libpsoc_helper

LOCAL_SHARED_LIBRARIES += libts libc libcutils

LOCAL_C_INCLUDES += bootable/bootloader/uboot-imx/tools/env \
                    external/tslib \
                    external/tslib/tests \
                    external/tslib/src \
                    external/utils/eeprom \
                    external/utils/PSoCUpdate
ifneq ($(PTEST_VERSION),)
LOCAL_CFLAGS := -DPTEST_VERSION=$(PTEST_VERSION)
endif


LOCAL_CFLAGS += -DUSE_HOSTCC \
                -DANDROID \
                -isystem bootable/bootloader/uboot-imx/include/ \
                -isystem bootable/bootloader/uboot-imx/arch/arm/include/

include $(BUILD_EXECUTABLE)
现在,错误消息表示存在对fw_printenv()、fw_setenv()和fw_printenv()的未定义引用。但是这些函数是在bootable/bootloader/uboot imx/tools/env中定义的,它们包含在
LOCAL\u C\u INCLUDES+=bootable/bootloader/uboot imx/tools/env
中,并且它们是
LOCAL\u STATIC\u库+=libfw
的一部分。为了完整起见,我还将包括负责U-Boot中libfw的Android.mk文件

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := fw_printenv

LOCAL_SRC_FILES :=  fw_env_main.c

LOCAL_C_INCLUDES += fw_env.h
LOCAL_STATIC_LIBRARIES := libfw

LOCAL_CFLAGS := -DUSE_HOSTCC \
                -DANDROID \
                -isystem$(LOCAL_PATH)/../../include/ \
                -isystem$(LOCAL_PATH)/../../arch/arm/include/


include $(BUILD_EXECUTABLE)

include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE:= libfw


LOCAL_SRC_FILES :=  fw_env.c \
                    ctype.c \
                    crc32.c \
                    env_attr.c \
                    env_flags.c \
                    aes.c
#since alot of duplicated Header files exist in uboot-imx/include/ we use -isystem here
#to search for the correct Headers in bionic first
LOCAL_CFLAGS := -DUSE_HOSTCC \
                -DANDROID \
                -isystem$(LOCAL_PATH)/../../include/ \
                -isystem$(LOCAL_PATH)/../../arch/arm/include/

LOCAL_C_INCLUDES += fw_env.h \
                    external/mtd-utils/new-utils/include/

include $(BUILD_STATIC_LIBRARY)

有人能指出我哪里出了问题吗。我已经浏览了在线文档(),以及上下stackoverflow。我对这个问题很迷惑。

< P> >从代码< Android > MK<代码>中看到,LIFFW是C库,而你的代码是C++。C和C++有不同的ABIs,所以链接器无法匹配C++代码中调用的函数,而不匹配C库中定义的函数。要防止此问题,请使用以下命令包括标题:

extern "C" {
#include "header_from_libfw.h"
}

这将指导C++编译器对这个头中定义的函数使用C-ABI,以便它们可以在连接期间与C库中定义的函数相匹配。具体来说,这将禁用C++风格的名称混乱()。

如何在代码中包含libfw的标题?看来你的代码是C++,libfw是C?您是否使用extern“C”{}来避免名称损坏问题?(见例句)我刚学到一些新东西,你解决了我的问题。各条战线上的胜利!谢谢,太好了。我会把它变成一个完整的答案,这样问题就可以标记为已回答。