AOSP - 错误:在构建过程中未定义对<function-name>的引用。

问题描述 投票:1回答:1

我需要另一个眼睛好的人告诉我,我在这里做错了什么。

我不得不升级我的设备上的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 文件,负责 set_display_orientation.cpp。.

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()的引用。. 但这些功能是在 可启动的bootloaderuboot-imxtoolsenv。 纳入《公约》的 LOCAL_C_INCLUDES += bootable/bootloader/uboot-imx/tools/env 而它们属于 LOCAL_STATIC_LIBRARIES += libfw. 为完整起见,我还将包括以下内容 Android.mk 文件,负责 libfw 是U-Boot的一部分。

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)

谁能指出我哪里做错了。我已经看了在线文档(https:/developer.android.comndkguidesandroid_mk。),以及上上下下的stackoverflow。我真的很迷茫。

c++ android-source android.mk
1个回答
2
投票

可以看到,从 Android.mk 对于libfw,它是一个C库,而你的代码是C++。C和C++有不同的ABI,所以链接器无法将你在C++代码中调用的函数与C库中定义的函数进行匹配。为了防止这个问题,请在头文件中使用。

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

这将指示C++编译器对该头中定义的函数使用C-ABI,这样在链接过程中就可以将它们与C库中定义的函数进行匹配。具体来说,这将禁用C++风格的名称混淆 (参考).

© www.soinside.com 2019 - 2024. All rights reserved.