I have a weird problem with my C-Code that I don't really understand.
I have two header files os_memory.h and os_mem_drivers.h.
os_memory.h
#ifndef OS_MEMORY_H_
#define OS_MEMORY_H_
#include "lcd.h"
#include "os_mem_drivers.h"
static const MemAddr gui_alloc_table_start = 0x1C8;
#endif /* OS_MEMORY_H_ */
os_mem_drivers.h
#ifndef OS_MEM_DRIVERS_H_
#define OS_MEM_DRIVERS_H_
#include "os_memory.h"
#include "defines.h"
#include "os_core.h"
typedef uint16_t MemAddr;
#endif
If I try to compile this code the compiler gives me the error unknown type name 'MemAddr'. I don't get it because I included the right header files in each .h file so there shouldn't be any error.
Is there anything that I'm missing here?
I'm using AtmelStudio 6.1 and the C language for this project.
You should move the definition for type MemAddr before including "os_memory.h":
os_mem_drivers.h:
#ifndef OS_MEM_DRIVERS_H_
#define OS_MEM_DRIVERS_H_
#include <stdint.h>
typedef uint16_t MemAddr;
#include "os_memory.h"
#include "defines.h"
#include "os_core.h"
#endif
But a more important problem is the circular inclusion of "os_memory.h" and "os_mem_drivers.h". Each one includes the other: include guards prevent recursive inclusion but make it difficult to understand what is really going on. You should try and fix this issue.
Related
when I compile Visualization folder, that is the error in Font_FTFont.cxx
I made the error go away by changing
#ifdef HAVE_FREETYPE
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
// changed to
#ifndef HAVE_FREETYPE
#include <ft2build.h>
#include FT_FREETYPE_H
#endif
I don't know how to fix the error and whether my change has major hidden issues?
Including main.h in stm32f4xx_hal_uart.h causes issues --> usart_app.h:14:22: error: unknown type name 'USART_Handle_t'; did you mean 'DMA_Handle_t'? -- mainly related to unknown types.
Aren't there easy ways around figuring out issues specific to file includes? cause it's annoying
I suspect stm32f4xx_dma.h is causing trouble since it's being called in main.h and stm32f4xx_hal_uart.h but I wonder wouldn't header guard take care of the 'loop`?
here's what i sort of have:
// --- main.h ---
#include "stm32f4xx_hal.h"
#include "mcp9808.h"
#include "usart_app.h"
#include "stm32f4xx_dma.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
// --- stm32f4xx_hal_uart.h ---"
#include <stdint.h>
#include "stdbool.h"
#include "../Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.h"
#include "stm32f4xx_dma.h"
#include "main.h" // ... adding this causes issues !!
typedef struct {
USART_TypeDef *pUSARTx;
USART_Config_t USART_Config;
USART_State USART_State;
char *txBuffer;
char *rxBuffer;
uint8_t txLength;
uint8_t rxLength;
uint8_t rxSize;
uint8_t dmaTransfer;
uint8_t dmaReception;
DMA_Handle_t *dmaRx;
DMA_Handle_t *dmaTx;
} USART_Handle_t;
// --- stm32f4xx_dma.h ---
#include "stm32f401xe.h"
#include "stm32f4xx_hal.h"```
… I wonder wouldn't header guard take care of the 'loop`?
What header guard? The file contents you show in the question do not have header guards.
If there are header guards, then the problem is that including main.h in stm32f4xx_hal_uart.h causes it to include usart_app.h, and usart_app.h needs the USART_Handle_t defined in stm32f4xx_hal_uart.h, so it includes stm32f4xx_hal_uart.h, but the earlier processing is already past the header guard in stm32f4xx_hal_uart.h, so the guard skips the body of stm32f4xx_hal_uart.h when usart_app.h includes it, so USART_Handle_t is not defined.
To fix that, do not include main.h in stm32f4xx_hal_uart.h.
I keep running into an issue while trying to include an enumeration from one header file in antoher.
The environment I am working in is embedded C using IAR Embedded Workbench.
I have a header file for dedicated enumerated types named "enums.h"
#ifndef ENUMS_H_
#define ENUMS_H_
typedef enum
{
SET,
SCHEDULE,
EXECUTE
}action_type_t;
#endif
and a header file for a parser named "parser.h"
#ifndef PARSER_H_
#define PARSER_H_
#include "enums.h"
#include <stdint.h>
typedef struct
{
action_type_t action;
uint16_t nbytes;
}Message;
#endif
In parser.c I include the header as
#include "parser.h"
When I compile this, I get the error "identifier action_type_t is undefined"
What am I doing wrong here? I am stumped at this point.
Thank you
Your enum definition is missing commas, your parser.h uses uint16_t while having failed to include <stdint.h> and, to be extra pedantic, your include guard macro is encroaching on the reserved namespace because it starts with _ and a capital letter.
This should work:
enums.h:
#ifndef ENUMS_H_
#define ENUMS_H_
typedef enum
{
SET,
SCHEDULE,
EXECUTE, /*the last comma is optional*/
}action_type_t;
#endif
parser.h:
#ifndef PARSER_H_
#define PARSER_H_
#include "enums.h"
#include <stdint.h>
typedef struct
{
action_type_t action;
uint16_t nbytes;
}Message;
#endif
Thank you to all who answered, I figured I would come back and close this one.
It turns out I had an identically named, but empty header file included in my project...
Next time i'll be better about looking in my own backyard first before asking others.
However PSkocik did provide a working example, and his code compiles perfectly for anyone who stumbles into this thread!
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 have two source files, main.c and datamgr.c - and two header files, config.h and datamgr.h
The testing system we're using expects these files, and only these files.
main.c:
#include "datamgr.h"
#include "config.h"
int main() {
custom_type a = 1;
a = foo();
return 0;
}
datamgr.c:
#include "datamgr.h"
#include "config.h"
custom_type foo() {
custom_type a = 1;
return a;
}
datamgr.h:
#ifndef DATAMGR_H
#define DATAMGR_H
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
custom_type foo();
#endif
config.h:
#ifndef CONFIG_H
#define CONFIG_H
#ifndef SET_MAX_TEMP
#error "Max temperature not set."
#endif
#ifndef SET_MIN_TEMP
#error "Max temperature not set."
#endif
typedef custom_type uint16_t
#endif
Now, the problem is that I can only define SET_MAX_TEMP and SET_MIN_TEMP in main.c, but both main.c and datamgr.c need both the header files. So if I leave them undefined in datamgr.c I get a compiler error. However, if I do define them in datamgr.c and later overwrite them in main.c, I get a different compiler error.
Please, any assistance as to how to get this horrible setup to work would be greatly appreciated.
You can pass these defines directly while compiling:
gcc -DSET_MAX_TEMP -DSET_MIN_TEMP <your files>
In datamgr.c do:
#define SET_MAX_TEMP
#define SET_MIN_TEMP
#include "datamgr.h"
#include "config.h"
#undef SET_MAX_TEMP
#undef SET_MIN_TEMP
In a comment, you said:
Because main.c is the file that our testing system uses to implement the test scenarios.
In that case, make sure that the testing system defines those macros in the command line of the compiler for every file being compiled.