'Undefined reference to' error

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey, so I face a linker issue (I assume so...) I am using a 'bmm050' driver where they have two pointers and a struct defined as:

 

#define BMM050_WR_FUNC_PTR \
	s8 (*bus_write)(u8, u8, \
	u8 *, u8)

#define BMM050_RD_FUNC_PTR \
	s8 (*bus_read)(u8, u8, \
	u8 *, u8)

struct bmm050_t {
	u8 company_id;/**<mag chip id*/
	u8 dev_addr;/**<mag device address*/

	BMM050_WR_FUNC_PTR;/**< bus write function pointer*/
	BMM050_RD_FUNC_PTR;/**< bus read function pointer*/
	void (*delay_msec)(BMM050_MDELAY_DATA_TYPE);/**< delay function pointer*/

	s8 dig_x1;/**< trim x1 data */
	s8 dig_y1;/**< trim y1 data */

	s8 dig_x2;/**< trim x2 data */
	s8 dig_y2;/**< trim y2 data */

	u16 dig_z1;/**< trim z1 data */
	s16 dig_z2;/**< trim z2 data */
	s16 dig_z3;/**< trim z3 data */
	s16 dig_z4;/**< trim z4 data */

	u8 dig_xy1;/**< trim xy1 data */
	s8 dig_xy2;/**< trim xy2 data */

	u16 dig_xyz1;/**< trim xyz1 data */
};

In my application I do the following to assign the function to the pointer:

bmm050.bus_write = i2c_write;
bmm050.bus_read = i2c_read;

Where the two functions are defined as follows:

int8_t i2c_write(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t count);
int8_t i2c_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t count);

After compiling I get errors:

Severity	Code	Description	Project	File	Line
Error		undefined reference to `_write'	Project1	C:\Users\ab\Documents\Atmel Studio\7.0\Project1\Project1\Debug\writer.c	1
Error		undefined reference to `_read'	Project1	C:\Users\ab\Documents\Atmel Studio\7.0\Project1\Project1\Debug\readr.c	1
Error		ld returned 1 exit status	Project1	collect2.exe	0

I tried changing the driver's code, etc. but to no avail. I now settled on the hypothesis that this is a linker's issue, however, I have no idea how to solve it... All suggestions are welcome!

 

 

 

 

 

 

This topic has a solution.
Last Edited: Fri. Nov 11, 2016 - 10:15 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The issue was solved. It seems that that one needs to explicitly include 'stdio' driver to the project using ASF manager.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

BurtTheH wrote:
Where the two functions are defined (sic) as follows:

int8_t i2c_write(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t count);
int8_t i2c_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t *reg_data, uint8_t count);

NO - those are just declarations (prototypes) - not definitions!

 

BurtTheH wrote:
It seems that that one needs to explicitly include 'stdio' driver to the project using ASF manager

That would provide the definitions!

 

http://c-faq.com/decl/decldef.html

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

please include  'stdio' driver 

 

 

if anyone  want to learn programming please visit this website 

 

 

http://www.computerprogrammingtu...

emran