我正在为机器人编写FRAM驱动程序,突然间我开始收到此错误:
C:\Users\james\AppData\Local\Temp\cciezvMm.o: In function `_FRAM_driver_setup':
(.text+0x0): multiple definition of `_FRAM_driver_setup'
cmm/FRAM_driver.o:(.text+0x0): first defined here
C:\Users\james\AppData\Local\Temp\cciezvMm.o: In function `_FRAM_log_data':
(.text+0xf): multiple definition of `_FRAM_log_data'
cmm/FRAM_driver.o:(.text+0xf): first defined here
C:\Users\james\AppData\Local\Temp\cciezvMm.o: In function `_FRAM_read_data':
(.text+0x7a): multiple definition of `_FRAM_read_data'
cmm/FRAM_driver.o:(.text+0x7a): first defined here
collect2: ld returned 1 exit status
Done. Build Failed!
我不确定是什么带来了这个,但我无法在我的代码中找到多个定义。这是头文件:
#ifndef FRAM_DRIVER_H_
#define FRAM_DRIVER_H_
#include "simpletools.h"
typedef struct FRAM_driver_type {
i2c* busID;
} FRAM_driver_type;
void FRAM_driver_setup(FRAM_driver_type* ptr, int sclPin, int sdaPin,
int sclDrive);
void FRAM_log_data(unsigned char* string, FRAM_driver_type* ptr);
void FRAM_read(FRAM_driver_type* ptr);
#endif
这是c文件:
#include "FRAM_driver.h"
#define FRAM_DEFAULT_ADDR (0x50)
#define FRAM_MAX_MEM_ADDRESS (0x00)
#define FRAM_FIRST_MEM_ADDR (0x01)
#define FRAM_ADDR_SIZE ( 2 )
#define FRAM_DATA_SIZE ( 1 )
#define INT_SIZE ( 1 )
void FRAM_driver_setup(FRAM_driver_type* ptr, int sclPin, int sdaPin,
int sclDrive){
ptr->busID = i2c_newbus(sclPin, sdaPin, sclDrive);
}
void FRAM_log_data(unsigned char* data, FRAM_driver_type* ptr){
// Create a static integer initialized to the first memory address of the
// FRAM. It is 0x01 instead of 0x00 because 0x00 is going to be used to
// store the last memory adress being used. Also, create the int data_Size
// and set it equal to the length of the string plus one.
//
static int mem_Addr = FRAM_FIRST_MEM_ADDR;
int data_Size = strlen(data) + 1;
// Send the size of the data being sent to the next available memory
// address. This allows the FRAM_read_data funtion to know what size of
// data to read. Then increment up by one memory address.
//
i2c_out(ptr->busID, FRAM_DEFAULT_ADDR, mem_Addr, FRAM_ADDR_SIZE, data_Size,
INT_SIZE);
while(i2c_busy(ptr->busID, FRAM_DEFAULT_ADDR));
mem_Addr += 0x01;
// Write data to the next address when the FRAM is not busy, then increment
// the memory address by one again.
//
i2c_out(ptr->busID, FRAM_DEFAULT_ADDR, mem_Addr, FRAM_ADDR_SIZE, data,
data_Size);
while(i2c_busy(ptr->busID, FRAM_DEFAULT_ADDR));
mem_Addr += 0x01;
// Write the last memory address used to the first memory address of the
// FRAM. Then wait for the FRAM to not be busy.
//
i2c_out(ptr->busID, FRAM_DEFAULT_ADDR, FRAM_FIRST_MEM_ADDR, FRAM_ADDR_SIZE,
mem_Addr, INT_SIZE);
while(i2c_busy(ptr->busID, FRAM_DEFAULT_ADDR));
}
void FRAM_read_data(FRAM_driver_type* ptr){
// Initialize unsigned characters to receive data from i2c_in.
//
unsigned char logged_Data = 1;
unsigned char logged_Data_Size;
unsigned char last_Memory_Address;
// Get the last memory address written to from FRAM_MAX_MEM_ADDRESS and
// store it in last_Memory_Address.
//
i2c_in(ptr->busID, FRAM_DEFAULT_ADDR, FRAM_MAX_MEM_ADDRESS, FRAM_ADDR_SIZE,
&last_Memory_Address, INT_SIZE);
while(i2c_busy(ptr->busID, FRAM_DEFAULT_ADDR));
// Loop through all of the filled memory addresses in the FRAM and print
// the logged data in each address.
//
for (int i = FRAM_FIRST_MEM_ADDR; i <= last_Memory_Address; i+=2){
// Get the data_Size from the odd memory address and store it in
// logged_Data_Size. Then wait until the FRAM isn't busy.
//
i2c_in(ptr->busID, i, FRAM_FIRST_MEM_ADDR,
FRAM_ADDR_SIZE, &logged_Data_Size, INT_SIZE);
while(i2c_busy(ptr->busID, FRAM_DEFAULT_ADDR));
// Use logged_Data_Size to store the data to logged_Data and then print
// the data. Wait until the FRAM isn't busy.
//
i2c_in(ptr->busID, i++, FRAM_FIRST_MEM_ADDR,
FRAM_ADDR_SIZE, &logged_Data, logged_Data_Size);
print("Log: %d \n", logged_Data);
while(i2c_busy(ptr->busID, FRAM_DEFAULT_ADDR));
}
}
最后,这是testbench文件:
#include "FRAM_driver.h"
#define FRAM_SCL_PIN 28
#define FRAM_SDA_PIN 29
static FRAM_driver_type fram_obj;
int main() {
const unsigned char* data = 2;
FRAM_driver_setup(&fram_obj, FRAM_SCL_PIN, FRAM_SDA_PIN, 0);
FRAM_log_data(data , &fram_obj);
FRAM_read_data(&fram_obj);
}
非常感谢任何帮助。另外,我正在为Propeller微控制器使用simpleIDE和simpletools库。
答案 0 :(得分:1)
C:\Users\james\AppData\Local\Temp\cciezvMm.o: In function '_FRAM_driver_setup:
(.text+0x0): multiple definition of '_FRAM_driver_setup' cmm/FRAM_driver.o:(.text+0x0): first defined here
此错误表示您的链接行引用了FRAM_driver.c
两次,看起来像这样:
gcc ... cmm/FRAM_driver.o ... cmm/FRAM_driver.c ...
不要那 - 它显然无法正常工作。
答案 1 :(得分:1)
SimpleIDE包含了一个未包含在项目目录中的文件的备份。实际上,我无法在任何地方找到它。就好像它正在创建我正在处理的代码的备份副本,然后每当我运行代码时将其存储在临时位置。该文件已从SimpleIDE项目文件中删除,然后运行。