C语言 Eclipse CDT 错误:“无法解析符号‘XXX’”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20051550/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 10:20:09  来源:igfitidea点击:

Eclipse CDT error: "Symbol 'XXX' could not be resolved"

ceclipseeclipse-cdt

提问by Eliot

I have an embedded C project that builds and runs just fine using make on the console, but Eclipse CDT is giving me errors.

我有一个嵌入式 C 项目,它在控制台上使用 make 构建和运行得很好,但是 Eclipse CDT 给了我错误。

In main.c, this function uses a macro, APP_BUTTON_INIT:

在 main.c 中,这个函数使用了一个宏,APP_BUTTON_INIT:

static void buttons_init(void)
{
    static app_button_cfg_t buttons[] =
    {
        {SIGNAL_ALERT_BUTTON,           false, NRF_GPIO_PIN_NOPULL, button_event_handler},
        {BONDMNGR_DELETE_BUTTON_PIN_NO, false, NRF_GPIO_PIN_NOPULL, NULL}
    };

    APP_BUTTON_INIT(buttons, sizeof(buttons) / sizeof(buttons[0]), BUTTON_DETECTION_DELAY, false);
}

The APP_BUTTON_INIT macro is defined in app_button.h like this:

APP_BUTTON_INIT 宏在 app_button.h 中定义如下:

#define APP_BUTTON_INIT(BUTTONS, BUTTON_COUNT, DETECTION_DELAY, USE_SCHEDULER)                     \
do                                                                                             \
{                                                                                              \
    uint32_t ERR_CODE = app_button_init((BUTTONS),                                             \
                                        (BUTTON_COUNT),                                        \
                                        (DETECTION_DELAY),                                     \
                                        (USE_SCHEDULER) ? app_button_evt_schedule : NULL);     \
    APP_ERROR_CHECK(ERR_CODE);                                                                 \
} while (0)

The error is

错误是

Symbol 'app_button_evt_schedule' could not be resolved

But that function is defined further down in the very same header file, app_button.h:

但该函数在同一个头文件 app_button.h 中进一步定义:

static __INLINE uint32_t app_button_evt_schedule(app_button_handler_t button_handler,
                                             uint8_t              pin_no)
{
    app_button_event_t buttons_event;

    buttons_event.button_handler = button_handler;
    buttons_event.pin_no         = pin_no;

    return app_sched_event_put(&buttons_event, sizeof(buttons_event), app_button_evt_get);
}

I've tried Project right click -> Index -> Rebuild and Freshen all files, no joy. I'm using Eclipse Kepler SR1 with CDT 8.2.1. Why can't Eclipse see this function?

我已经尝试过 Project 右键单击​​ -> 索引 -> 重建和刷新所有文件,没有任何乐趣。我正在使用带有 CDT 8.2.1 的 Eclipse Kepler SR1。为什么Eclipse看不到这个功能?

The first operation of the makefile is this (this works):

makefile 的第一个操作是这样的(这有效):

mkdir _build
"/Users/Eliot/dev/gcc-arm/bin/arm-none-eabi-gcc" -DNRF51822_QFAA_CA -mcpu=cortex-m0 -mthumb -mabi=aapcs -DNRF51 -DBOARD_NRF6310 -DNRF51822_QFAA_CA --std=gnu99 -Wall -Werror -mfloat-abi=soft -DDEBUG -g3 -O0 -I"/Users/Eliot/dev/nrf51822/Include/ble" -I"/Users/Eliot/dev/nrf51822/Include/ble/softdevice" -I"/Users/Eliot/dev/nrf51822/Include/app_common" -I"/Users/Eliot/dev/nrf51822/Include/ble/ble_services" -I"../" -I"/Users/Eliot/dev/nrf51822/Include" -I"/Users/Eliot/dev/nrf51822/Include/gcc" -I"/Users/Eliot/dev/nrf51822/Include/ext_sensors" -M ../main.c -MF "_build/main.d" -MT _build/main.o

Screenshots for my CDT project config for includes, symbols and the tool chain are here:

我的包含、符号和工具链的 CDT 项目配置的屏幕截图在这里:

https://dl.dropboxusercontent.com/u/12173473/screenshot_cdt_includes.pnghttps://dl.dropboxusercontent.com/u/12173473/screenshot_cdt_symbols.pnghttps://dl.dropboxusercontent.com/u/12173473/screenshot_cdt_toolchain.png

https://dl.dropboxusercontent.com/u/12173473/screenshot_cdt_includes.png https://dl.dropboxusercontent.com/u/12173473/screenshot_cdt_symbols.png https://dl.dropboxusercontent.com/u/12173473/screenshot_cdt_toolchain PNG

I'm not using a toolchain because my project started out as the sample CDT project from the hardware manufacturer (Nordic Semiconductor) and that project also had no toolchain configured. To be honest, I doubt CDT is finding the right gcc executable.

我没有使用工具链,因为我的项目是作为硬件制造商 (Nordic Semiconductor) 的示例 CDT 项目开始的,并且该项目也没有配置工具链。老实说,我怀疑 CDT 是否找到了正确的 gcc 可执行文件。

采纳答案by Eliot

Self-answering. Running around without a proper toolchain configured in Eclipse was the problem. For ARM development using cross gcc, this Eclipse plugin fixed my problem and looks promising in general. It gives you Eclipse project settings for the whole toolchain and means you can ditch your makefiles.

自答。在没有在 Eclipse 中配置适当工具链的情况下四处奔波是问题所在。对于使用 cross gcc 的 ARM 开发,这个 Eclipse 插件解决了我的问题,总体上看起来很有希望。它为您提供了整个工具链的 Eclipse 项目设置,这意味着您可以放弃生成文件。

http://gnuarmeclipse.github.io

http://gnuarmeclipse.github.io

回答by ericbn

Your Eclipse project must refect the same behavior as your makefile.

您的 Eclipse 项目必须反映与您的 makefile 相同的行为。

Match the output of make(i.e. the calls to gccor whatever compiler and linker you are using) with your Eclipse project settings at Properties > C/C++ Build > Settings. I would start looking at the include paths (-I) and the defined symbols (-D), and then at the other flags.

将输出make(即调用gcc或您使用的任何编译器和链接器)与属性 > C/C++ 构建 > 设置中的 Eclipse 项目设置相匹配。我将开始查看包含路径 ( -I) 和定义的符号 ( -D),然后查看其他标志。

Unfortunately, Eclipse is not very clever in importing projects from makefiles, nor at resolving compiler and linker settings from external build tools.

不幸的是,Eclipse 在从 makefile 导入项目以及从外部构建工具解析编译器和链接器设置方面不是很聪明。