Does the header file couldn't include another header file in C?
I download the code from Nuvoton website, for Keil C51 project, use the UART sample code, just add the file "EasyTransfer.h" and include "Typedef.h", the result shows lots of error message below.
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(1): error C231: 'BIT': redefinition
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(2): error C231: 'UINT8': redefinition
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(3): error C231: 'UINT16': redefinition
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(4): error C141: syntax error near 'UINT32'
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(6): error C231: 'uint8_t': redefinition
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(7): error C231: 'uint16_t': redefinition
\N79E85x_Sample_Code_V1.0.8(1)\Include\Typedef.h(8): error C141: syntax error near 'uint32_t'
The "EasyTransfer.h" is simple, just few of lines
#ifndef EasyTransfer_h
#define EasyTransfer_h
#include "Typedef.h"
uint8_t * address; //address of struct
#endif
The following is the main code and source link, I think it could be helpful to understand my question.
#define Uart_Port_Sel 0x00
#include <stdio.h>
#include "N79E85x.h"
#include "Typedef.h"
#include "Define.h"
#include "Common.h"
#include "Delay.h"
#include "Version.h"
#include "EasyTransfer.h"
UINT8 u8Uart_Data;
//-----------------------------------------------------------------------------------------------------------
void main (void)
{
AUXR1 |= Uart_Port_Sel; // Select P10/P11 as UART pin(default)
InitialUART0_Timer1(9600); // 9600 Baud Rate # 11.0592MHz
Show_Version_Number_To_PC();
ES = 1; // Enable serial interrupt
EA = 1; // Enable global interrupt
while(1); // Endless
}
//-----------------------------------------------------------------------------------------------------------
void UART_ISR(void) interrupt 4
{
if (RI == 1)
{ // If reception occur
RI = 1; // Clear reception flag for next reception
u8Uart_Data = SBUF; // Read receive data
SBUF = u8Uart_Data; // Send back same data on UART
}
else TI = 0; // If emission occur
// Clear emission flag for next emission
}
You should not include Typedef.h multiple times since there is no header include guard in Typedef.h.
Your main source includes Typedef.h and EasyTransfer.h at the same time, this causes redefinition errors because EasyTransfer.h includes Typedef.h too. Just like your main source includes Typedef.h twice, and WITHOUT header include guard!
I suggest you just remove the #include "Typedef.h" line from your main source file. Or add header include guard in Typedef.h if you can.
Related
Hi I'm working on watchdog but I'm bit confused It show me some errors. I'm using AVR(AVR128DB48).
Errors:
WDTO_4S' undeclared (first use in this function)
recipe for target 'main.o' failed
code:
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/wdt.h>
int main(void)
{
wdt_enable(WDTO_4S);
while(1)
{
wdt_reset();
}
return(0);
}
Never used this part, but I can do a quick Google search. From the inline documentation the header itself:
#define WDTO_4S 8
Note: This is only available on the ATtiny2313, ATtiny24, ATtiny44, ATtiny84, ATtiny25, ATtiny45, ATtiny85, ATtiny261, ATtiny461, ATtiny861, ATmega48, ATmega88, ATmega168, ATmega48P, ATmega88P, ATmega168P, ATmega328P, ATmega164P, ATmega324P, ATmega644P, ATmega644, ATmega640, ATmega1280, ATmega1281, ATmega2560, ATmega2561, ATmega8HVA, ATmega16HVA, ATmega32HVB, ATmega406, ATmega1284P, AT90PWM1, AT90PWM2, AT90PWM2B, AT90PWM3, AT90PWM3B, AT90PWM216, AT90PWM316, AT90PWM81, AT90USB82, AT90USB162, AT90USB646, AT90USB647, AT90USB1286, AT90USB1287, ATtiny48, ATtiny88.
See Here
So I'm making a function called reboot, but when I define it the compiler gives an error like the function is already defined.
Here is bios.c:
#include "bios.h"
#include <stdint.h>
#include <libasm/asm.h>
void reboot()
{
uint8_t good = 0x02;
while (good & 0x02)
good = EmeraldASM_inb(0x64);
EmeraldASM_outb(0x64, 0xFE);
asm volatile("hlt");
}
here is bios.h :
#ifndef BIOSPOWER_H
#define BIOSPOWER_H
#pragma once
void reboot();
extern void shutdown();
#endif
here is the compiler error: /home/abbix/Documents/Projects/emerald/src/firmware/bios.c:5: multiple definition of `reboot'; src/firmware/bios.o:/home/abbix/Documents/Projects/emerald/src/firmware/bios.c:5: first defined here
Here is my Makefile:
https://pastebin.com/xCcQEtx3
The problem was that my assembly file had the name bios.asm, so it created two bios.o that was what caused the error (thanks to Eric Postpischil)
I have a stupid problem and I don't see where it comes from. I took care of using #ifndef directive to make sure all my #include are not redefined. Sadly for three of them that's happening. Here my multiple files arch :
t_include.h
#ifndef T_INCLUDE_H_
#define T_INCLUDE_H_
/* Project specific dependencies*/
#include "utilities.h"
#include "fsp_function.h"
#include "ti/csl/csl_tsc.h"
#include "ti/csl/csl_cache.h"
#include "ti/csl/csl_cacheAux.h"
#include "ti_sp_complex_convolution_A_input1.h"
#include "ti_sp_complex_convolution_A_input2.h"
#include "to_sp_complex_convolution_A_output.h"
#endif /* T_INCLUDE_H_ */
t_function.h
#ifndef T_FUNCTION_H_
#define T_FUNCTION_H_
#include "t_include.h"
/*output vector*/
#define INPUT1A_LENGTH 5000
#define INPUT2A_LENGTH 2800
#define OUTPUTA_LENGTH 2202
extern FLOAT32 sp_complex_convolution_A_output_thales[OUTPUTA_LENGTH];
/*misc parameter*/
#define CPU_CLOCK_KHZ 1400000
#define CPU_CLOCK_MS 1/CPU_CLOCK_KHZ
#define FIR_NB_MACS INPUT1A_LENGTH * OUTPUTA_LENGTH /* FIR algorithm complexity */
#define NB_OF_REP 10
#define UMA_L2CACHE_L1DCACHE 0
/* Project specific types */
typedef struct{
ect...
And now c file only include t_function.h :
t_function.c
/* Dependencies */
#include "t_function.h"
FLOAT32 sp_complex_convolution_A_output_thales[OUTPUTA_LENGTH];
/* API */
etc...
And t_main_function.c
/* dependencies */
#include "t_function.h"
void main(void) {
etc...
It should work but during linking here the errors comming :
<Linking>
error #10056: symbol "sp_complex_convolution_A_output" redefined: first defined in "./TEST/t_function.obj"; redefined in "./TEST/t_main_function.obj"
error #10056: symbol "sp_complex_convolution_A_input2" redefined: first defined in "./TEST/t_function.obj"; redefined in "./TEST/t_main_function.obj"
error #10056: symbol "sp_complex_convolution_A_input1" redefined: first defined in "./TEST/t_function.obj"; redefined in "./TEST/t_main_function.obj"
error #10056: symbol "sp_complex_convolution_A_output_thales" redefined: first defined in "./TEST/t_function.obj"; redefined in "./TEST/t_main_function.obj"
>> Compilation failure
error #10010: errors encountered during linking; "CONVOLUTION_COMPLEX.out" not built
So the error only com from three symbol sp_complex_convolution_A_output, sp_complex_convolution_A_input1 and sp_complex_convolution_A_input2 Which are defined in their own .h which is also protected by #ifndef directives:
ti_sp_complex_convolution_A_input1.h
#ifndef __TI_SP_COMPLEX_CONVOLUTION_A_INPUT1_H_
#define __TI_SP_COMPLEX_CONVOLUTION_A_INPUT1_H_
FLOAT32 sp_complex_convolution_A_input1[2 * 2500] = {
etc...
And the same for the other two...
So I really don't know why it is happening.
Thx for helping
Definitions like:
FLOAT32 sp_complex_convolution_A_output_thales[OUTPUTA_LENGTH];
should go into a source file.
The header files should contain only declarations like:
extern FLOAT32 sp_complex_convolution_A_output_thales[OUTPUTA_LENGTH];
As a rule of thumb, do no put anything that allocates memory into header files.
I am getting the below error when i try to compile my code. The code is not complete since i am yet to add functions in my header and source files. But only with definitions i am having these errors.
Error:
'Building target: UART_example.elf'
'Invoking: ARM gcc linker'
arm-xilinx-eabi-gcc -Wl,-T -Wl,../src/lscript.ld -L../../test_bsp/ps7_cortexa9_0/lib -o "UART_example.elf" ./src/helloworld.o ./src/platform.o ./src/uart_new.o -Wl,--start-group,-lxil,-lgcc,-lc,--end-group
./src/uart_new.o:(.data+0x0): multiple definition of `uart_fifo_rxptr'
./src/helloworld.o:(.data+0x0): first defined here
./src/uart_new.o:(.data+0x4): multiple definition of `uart_rxbuf'
./src/helloworld.o:(.data+0x4): first defined here
./src/uart_new.o:(.data+0x8): multiple definition of `uart1_tx'
./src/helloworld.o:(.data+0x8): first defined here
./src/uart_new.o:(.data+0xc): multiple definition of `uart2_tx'
./src/helloworld.o:(.data+0xc): first defined here
collect2.exe: error: ld returned 1 exit status
make: *** [UART_example.elf] Error 1
My uart_new.c source file just contains the include of uart_new.h header.
Content of uart_new.h is shown below
#ifndef UART_NEW_H_
#define UART_NEW_H_
#include "xparameters.h"
// address offset for the UART Peripheral
#define BASE_UART_BUFFER 0x4800
#define BASE_UART_REGS 0x4C00
unsigned *uart_fifo_rxptr = XPAR_SIGNAL_CONNECTOR_0_S00_AXI_BASEADDR + BASE_UART_REGS*4; // register 0
unsigned *uart_rxbuf = XPAR_SIGNAL_CONNECTOR_0_S00_AXI_BASEADDR + BASE_UART_BUFFER*4 ; // dual-port RAM
//--UART1 and UART2 transmit byte at registers 1 and 2
unsigned *uart1_tx = XPAR_SIGNAL_CONNECTOR_0_S00_AXI_BASEADDR + (BASE_UART_REGS +1)*4; // register 1
unsigned *uart2_tx = XPAR_SIGNAL_CONNECTOR_0_S00_AXI_BASEADDR + (BASE_UART_REGS +2)*4; // register 2
#endif /* UART_NEW_H_ */
And my main contains as shown below
#include <stdio.h>
#include "platform.h"
#include "uart_new.h"
void print(char *str);
int main()
{
//code
}
Please let me know if i am making any mistake somewhere.
I am assuming the error is linker related but cannot solve.
Thanks for help in advance!!
You've defined some global variables in a header file. These global variables will subsequently be defined in each source file (compilation unit) that includes the header file, resulting in multiple definitions.
To fix, change your definitions to declarations in the header file:
unsigned *uart_fifo_rxptr, *uart_rxbuf, *uart1_tx, *uart2_tx;
and put the definitions in only one source file.
I was trying to seperate my old working code in modules but I got always this error.
"nfc_read.h:24: error: expected ')' before '*' token"
this is line 24:
void read_card(boolean *success,uint8_t *uid,uint8_t *uidLength);
not sure what is wrong in the code...
In my header nfc_read.h:
#ifndef _nfc_read_h_
#define _nfc_read_h_
//Libarys
#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>
void setup_adafruit(int mode);
void read_card(boolean *success,uint8_t *uid,uint8_t *uidLength);//<--here is the error
#endif
Maybe here is the mistake somewhere:
#include "nfc_read.h"
#define IRQ (2) // IRQ = Interrupt request uint8 (input)
#define RESET (3) // Not connected by default on the NFC Shield uint8 (output)
void setup_adafruit(int mode)
{
Adafruit_NFCShield_I2C nfc(IRQ, RESET); //Funktionspointer....Pins konfigurieren IRQ => input ,RESET => output
Serial.println("Welcome this application will read your UID of your ISO14443A-Card"); //Willkommens Text
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find Arduino board");
while (1); // halt
}
nfc.setPassiveActivationRetries(0xFF);
// configure board to read RFID tags
nfc.SAMConfig();
Serial.println("Waiting for an ISO14443A card");
}
void read_card(boolean *success,uint8_t *uid,uint8_t *uidLength)
{
*success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
}
Perhaps this will help?
#ifndef _nfc_read_h_
#define _nfc_read_h_
//Libarys
#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>
Add the following lines:
#include <stdint.h>
#ifndef boolean
#define boolean int
#endif
The above lines will ensure that the proper types are defined.
void setup_adafruit(int mode);
void read_card(boolean *success,uint8_t *uid,uint8_t *uidLength);//<--here is the error
#endif