I have a common header file being included in multiple cpp files I then compile to make the .so files of each cpp . But when I execute with the final executable, I am seeing that the common header file is being duplicated in the sense that all statements in that header file are being hit as many times as it has been included in the cpp.
How to avert it?
The common header file is:
// common.h
#ifndef _COMMON_H
#define _COMMON_H
#include<iostream>
int funcC();
const int x = funcC();
#endif // COMMON_H
The other files are:
// common.c
#include "common.h"
#include <iostream>
int funcC() {
std::cout<<"HI HI HI"<<std::endl;
return 2;
}
and
// main1.c
#include "common.h"
int main() {
return 0;
}
I was expecting it you print "HI Hi Hi" only once, but it's printing twice