cancel
Showing results for 
Search instead for 
Did you mean: 

How to solve "undefined reference" when compiling

LucHardware
Associate III

I took the driver from Arduino for ADS119X and implement the HAL code for STM.

When compiling, it gives me “undefined reference to `keepSetting'�?. First I tought on a code problem but after long time of trail and error, I was looking on forums. It’s mentioned that there is some link problem. I try to solve it but no result.

In ADS119X.c I have:

#include "ADS119X.h"
#include "stm32l4xx_hal.h"
 
uint8_t ADS119X_keepSetting(uint8_t address)
{
   return _regData[address];
}
void ADS119X_setChannelSettings(uint8_t _address, uint8_t pwdownSetting, uint8_t gainSetting, uint8_t muxSetting )
{
	uint8_t _valueToWrite = keepSetting(_address) & ~(ADS119X_CHnSET_PD_MASK | ADS119X_CHnSET_GAIN_MASK | ADS119X_CHnSET_MUX_MASK) ;
    _valueToWrite |= (pwdownSetting & ADS119X_CHnSET_PD_MASK ) | (gainSetting   & ADS119X_CHnSET_GAIN_MASK) | (muxSetting    & ADS119X_CHnSET_MUX_MASK)  ;
    WREG(_address , _valueToWrite);
}
void ADS119X_setAllChannelSettings(uint8_t pwdownSetting, uint8_t gainSetting, uint8_t muxSetting )
{
 for (uint8_t address = ADS119X_ADD_CH1SET; address < ADS119X_ADD_CH1SET +  _num_channels ; address++) {
   setChannelSettings(address, pwdownSetting, gainSetting, muxSetting ) ;
 }
}
void ADS119X_setAllChannelGain(uint8_t gainSetting )
{
 for (uint8_t address = ADS119X_ADD_CH1SET; address < ADS119X_ADD_CH1SET +  _num_channels ; address++) {
   setChannelSettings(address, keepSetting(address), gainSetting, keepSetting(address)) ;
 }
}
void ADS119X_setAllChannelMux(uint8_t muxSetting )
{
 for (uint8_t address = ADS119X_ADD_CH1SET; address < ADS119X_ADD_CH1SET +  _num_channels ; address++) {
   setChannelSettings(address, keepSetting(address), keepSetting(address), muxSetting ) ;
 }
}

undefined reference to `keepSetting'

In ADS119X.h I have:

#ifndef INC_ADS119X_H_
#define INC_ADS119X_H_
 
#include "stm32l4xx_hal.h"
void setAllChannelMux(uint8_t muxSetting );
void setAllChannelGain(uint8_t gainSetting );
uint8_t keepSetting(uint8_t address);
…….
#endif /* INC_ADS119X_H_ */

The code is similar to ADS119X_setAllChannelGain but never has a problem with this part, also when I put “ADS119X_setAllChannelGain�? in comment. A full clean didn’t help. Google refers to “Paths and Symbols�? but what must be added?

Thanks for suggestions

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Do you define keepSetting somewhere? You haven't shown it in the code you posted.

Ensure it's defined (with an actual body, not just declared), and that the source file which defines it is getting compiled.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Guru

Do you define keepSetting somewhere? You haven't shown it in the code you posted.

Ensure it's defined (with an actual body, not just declared), and that the source file which defines it is getting compiled.

If you feel a post has answered your question, please click "Accept as Solution".
LucHardware
Associate III

Ooh yes, if I use in the code ADS119X_keepSetting and do this for the other errors, the undefined reference are gone. Thanks a lot, now I can continue.