Problem: A variable 'VarOriginal' is defined in source C file under pragma say 'parameterX' and declared as an extern variable in a header file under the same pragma 'parameterX'. There is a process using it in which it is known that the variable is shown declared in some other header file where this variable is not present at all.
As a Workaround:I declared one more different variable 'VarNew' before the pragma 'parameterX' in the header file and similarly defined the variable 'VarNew' before the line where 'VarOriginal' was defined. And it all worked.
Header file: header_file_with_problem.h
#ifndef HEADER_FILE_WITH_PROBLEM_H
#define HEADER_FILE_WITH_PROBLEM_H
#include "ABC.h"
declare variable 'VarNew' here <------
#pragma BSS(".parameterX")
extern int VarOriginal;
#pragma BSS(DEFAULT_SECTION_BSS)
Source C File:
#define HEADER_FILE_WITH_PROBLEM_C
#include "XYZ.h"
#include "header_file_with_problem.h"
declare variable 'VarNew' here <------
#pragma BSS(".parameterX")
int VarOriginal;
#pragma BSS(DEFAULT_SECTION_BSS)
But I am not able to understand why the problem was coming earlier. Why was the linker not able to find the definition of 'VarOriginal' in the source file and now it is able to do so, after declaring another variable before 'VarOriginal' itself?
Also, this problem is not with all source and header files present in the folder, but only a few of them.
A variable "A"... and pragma say "X" and a "B" before "A" and "J" and say "C" and maybe "Y" or "Z"
reads like nonsense and makes it very hard to understand your actual problem. Also remember that we can't see your monitor from here; the only information we have is what you provide us. The more clearly and concisely you can state your question, the more likely you'll get help quickly. – Ken White#pragma once
instead of regular multiple inclusion guards – Praetorian