gpt4 book ai didi

C Collect2 多重定义错误

转载 作者:太空宇宙 更新时间:2023-11-04 02:36:40 26 4
gpt4 key购买 nike

<分区>

我正在为机器人编写 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));
}
}

最后,这是测试台文件:

#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 微 Controller 使用 simpleIDE 和 simpletools 库。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com