简体   繁体   English

“未定义引用”不知道为什么?

[英]“Undefined reference to” no idea why?

Im working on a project for stm32f4 to my school. 我正在为我的学校从事stm32f4的项目。 Im using CooCox IDE. 我正在使用CooCox IDE。

I wanted to add new files "przerwania.c" and "przerwania.h" to write some functions there - not in "main.c". 我想添加新文件“ przerwania.c”和“ przerwania.h”以在其中编写一些功能,而不是在“ main.c”中。 But I have no idea why CooCox is showing me errors. 但是我不知道为什么CooCox向我显示错误。 Earlier I wanted to move some of functions from main.c to pwm.c and them work! 早些时候,我想将一些功能从main.c移至pwm.c,它们可以正常工作! But I would like to make a new files couse i have more functions. 但是我想制作一个新文件,因为我有更多功能。

Errors in CooCox look like this: CooCox中的错误如下所示:

[mkdir] Created dir: D:\CooCox\CoIDE\workspace\testowy2\testowy2\Debug\obj
   [cc] 12 total files to be compiled.
   [cc] arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -Wall -ffunction-sections -g -O0 -c -DSTM32F407VG -DSTM32F4XX -DUSE_STDPERIPH_DRIVER -D__ASSEMBLY__ -ID:\CooCox\CoIDE\workspace\testowy2 -ID:\CooCox\CoIDE\workspace\testowy2\cmsis_boot -ID:\CooCox\CoIDE -ID:\CooCox\CoIDE\workspace\testowy2\cmsis_lib\include -ID:\CooCox\CoIDE\workspace\testowy2\cmsis -ID:\CooCox\CoIDE\workspace\testowy2\cmsis_lib -ID:\CooCox\CoIDE\workspace D:\CooCox\CoIDE\workspace\testowy2\cmsis_lib\source\stm32f4xx_syscfg.c D:\CooCox\CoIDE\workspace\testowy2\pwm.c D:\CooCox\CoIDE\workspace\testowy2\dupa.c D:\CooCox\CoIDE\workspace\testowy2\cmsis_boot\startup\startup_stm32f4xx.c D:\CooCox\CoIDE\workspace\testowy2\main.c D:\CooCox\CoIDE\workspace\testowy2\cmsis_lib\source\stm32f4xx_rcc.c D:\CooCox\CoIDE\workspace\testowy2\cmsis_lib\source\stm32f4xx_adc.c D:\CooCox\CoIDE\workspace\testowy2\cmsis_lib\source\stm32f4xx_gpio.c D:\CooCox\CoIDE\workspace\testowy2\cmsis_boot\system_stm32f4xx.c D:\CooCox\CoIDE\workspace\testowy2\cmsis_lib\source\stm32f4xx_exti.c D:\CooCox\CoIDE\workspace\testowy2\cmsis_lib\source\misc.c D:\CooCox\CoIDE\workspace\testowy2\cmsis_lib\source\stm32f4xx_tim.c
   [cc] Starting link
   [cc] arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -g -nostartfiles -Wl,-Map=testowy2.map -O0 -Wl,--gc-sections -LD:\CooCox\CoIDE\configuration\ProgramData\testowy2 -Wl,-TD:\CooCox\CoIDE\configuration\ProgramData\testowy2/arm-gcc-link.ld -g -o testowy2.elf ..\obj\stm32f4xx_syscfg.o ..\obj\pwm.o ..\obj\dupa.o ..\obj\startup_stm32f4xx.o ..\obj\main.o ..\obj\stm32f4xx_rcc.o ..\obj\stm32f4xx_adc.o ..\obj\stm32f4xx_gpio.o ..\obj\system_stm32f4xx.o ..\obj\stm32f4xx_exti.o ..\obj\misc.o ..\obj\stm32f4xx_tim.o
   [cc] ..\obj\main.o: In function `main':
   [cc] D:\CooCox\CoIDE\workspace\testowy2/main.c:336: undefined reference to `Nowafunkcja'
   [cc] collect2.exe: error: ld returned 1 exit status

main.c is quite long becouse i have some definitions of few long functions there, so I paste here only a part main.c相当长,因为我在那里有一些长函数的一些定义,所以我在这里只粘贴了一部分

 #include "stm32f4xx.h"
 #include "misc.h"
 #include "stm32f4xx_syscfg.h"
 #include "stm32f4xx_adc.h"
 #include "stm32f4xx_exti.h"


 #include "przerwania.h"//here is the problem
 #include "pwm.h"

int main(void)
{


    SystemInit();
    //IniDiody();
    //TimConfig();
    //NVIC_Config();
    //IniDiodyPWM();

    LEDInit();
    EXTILine0_Config();

    PWM2();//wiwo
    GPIO();//wiwo

    Nowafunkcja();//PROBLEM


    RCC_Konfiguracja_Adc12();

    GPIO_Configuration_Adc1();
    ADC1_Configuration();
    GPIO_Configuration_Adc1();
    GPIO_Configuration_Adc2();
    ADC2_Configuration();

    IniDiody(GPIO_Pin_14);
    IniTimerPrzerwanie1();


    while(1)
    {
         ADC_SoftwareStartConv(ADC1);
         ADC_SoftwareStartConv(ADC2);
         while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET);
         wynikADC1 = (float)ADC_GetConversionValue(ADC1);
         while(ADC_GetFlagStatus(ADC2, ADC_FLAG_EOC) == RESET);
         wynikADC2 = (float)ADC_GetConversionValue(ADC2);
         wartosc = (int)(wynikADC2 * 15);
         //doPWM=(((float)ADCResult) / 41);
         //wartosc = (int) doPWM;
         //TIM2->CCR3 = (int) doPWM;

         TIM3->CCR2 = 65535;
         TIM3->CCR1 = wartosc;//(int)(wynikADC2 * 15);
         wartoscPrescalera=(int)SystemCoreClock;
    }


}

and files: przerwania.h 和文件:przerwania.h

#ifndef __przerwaniah
#define __przerwaniah



void Nowafunkcja(void);



#endif

przerwania.c przerwania.c

#include "przerwania.h"


void Nowafunkcja(void)
{
//nothing here - just for test
}

Do you have any idea what is the problem? 你知道是什么问题吗? I'm thinking about this since yesterday and its wird :/ I'll appreciate your help! 自昨天以来,我一直在考虑这个问题://感谢您的帮助!

Take a look at the line under [cc] 12 total files to be compiled. 看一下[cc] 12 total files to be compiled.下的一行[cc] 12 total files to be compiled. When you added pwm.c, you also informed the compiler to include this file. 添加pwm.c时,还通知编译器包括此文件。 You'll see it listed there. 您会在此处看到它。 przerwania.c is not. przerwania.c不是。 If you add przerwania the same way you added pwm, your IDE will take care of making sure it is included in the build. 如果以与添加pwm相同的方式添加przerwania,则IDE将确保确保它已包含在构建中。

I'm not sure what your current file/folder structure looks like: http://www.coocox.org/CoIDE/Project_management_config.html can help you determine how to pull those new files into the build. 我不确定您当前的文件/文件夹结构是什么样子: http : //www.coocox.org/CoIDE/Project_management_config.html可以帮助您确定如何将这些新文件拉入构建版本。

FWIW: The (anthropomorphized) compiler step says: Is this valid code? FWIW :(拟人化的)编译器步骤说:这是有效的代码吗? So it looks though your main.c, sees that you included przerwania.h, and comes to the conclusion that you correctly used the Nowafunkcja function (just matched the signature). 因此,它看起来像是您的main.c,看到您包含przerwania.h,并得出结论,您正确使用了Nowafunkcja函数(仅与签名匹配)。 Even though at this point, it has NOT looked into przerwania.c to find out what it does. 即使在这一点上,它也没有调查przerwania.c来找出其作用。 The compiler goes on to do this for all of your files and keeps track of what functions are defined in each file. 编译器继续对您的所有文件执行此操作,并跟踪每个文件中定义了哪些功能。 Note that it never found the definition Nowafunkcja, because the compiler never compiled przerwania.c. 请注意,它从未找到定义Nowafunkcja,因为编译器从未编译过przerwania.c。 It did however find the declaration in the .h (because main.c told it exactly where to find the .h) 但是,它确实在.h中找到了声明(因为main.c告诉了它确切的位置是.h的位置)

The linker then gets this stuff from the compiler, including what functions have been defined in all your .c files. 然后,链接器从编译器获取这些内容,包括在所有.c文件中定义了哪些功能。 That's the first point where something tries to answer the question "Now what code do I actually need to run when he asked me to Nowafunkcja()?". 这是某些问题试图回答“当他问我到Nowafunkcja()时,我现在实际上需要运行什么代码?”这一问题的第一点。 So that's the first point in the build when the tools realized, I never found code for Nowafunkcja in any of the .c files I was looking in. 因此,这是构建工具时实现的第一点,我从未在所查找的任何.c文件中找到Nowafunkcja的代码。

So, I think that roughly answers "Why", but we need to know more about your project organization to give you a "fix" to make it work. 因此,我认为这大致可以回答“为什么”,但是我们需要更多地了解您的项目组织,以便为您提供“解决方案”以使其正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM