0

267 / 5.000 Resultados de tradução Sorry for the English, but I'm trying to compile a simple code and it's giving an error of "undefined reference to `HAL_TIM_Base_Init'".

My code:

#include "main.h"
#include "rf_driver_hal_tim.h"

TIM_HandleTypeDef htim1;

static void mxtim1(void);


/**
 * @brief  The application entry point.
 * @retval int
 */
int main(void) {

    /* System initialization function */
    if (SystemInit(SYSCLK_64M, BLE_SYSCLK_NONE) != SUCCESS){
        /* Error during system clock configuration take appropriate action */
        while (1);
    }

    HAL_Init();
    IRQHandler_Config();
    MX_GPIO_Init();
    MX_USART1_UART_Init();
    mxtim1();

    while (1) {

    }
}

static void mxtim1(void){
    HAL_TIM_Base_Init(&htim1);  //error: undefined reference to `HAL_TIM_Base_Init'
}

I already called the Timer library in the main file, but even so the error persists, I expected that if I called this library all the files that would be in it would be seen by main.c.

  • Welcome to SO. There is some misconception: Calling a function does not bring it in. It's the opposite: If you want to call a function, the implementation must be provided. You must compile and link the C file that defines that function with your own code. – Gerhardh Dec 05 '22 at 16:32
  • What is your linking command line — do you list the libraries correctly? Have you checked the spelling of the function name? (I assume you have, and a Google search indicates that it is a valid name, so that isn't the problem.). So, back to the command line — what libraries are you using, and what order are you listing them in, and so on. – Jonathan Leffler Dec 05 '22 at 16:34
  • Gerhardh, muito obrigado, de fato o que estava faltando era o arquivo .c que define a função, por isso estava dando erro de "referencia indefinida". Muitíssimo obrigado pela ajuda! – Weslley Fabio Dec 21 '22 at 12:15

0 Answers0