how to avoid multiple inclusion problem

Hello,
I am writing a program that needs to include hw/nicinfo.h in more
then one file. Now the problem is everything i build the project, I get
“multiple definitions of” problem. I tried to use extern macro and
ifndef/define macro also to include the header file but nothing is working.
There is no way around but to include the header file in different files.
Can someone please tell me how can I build a project that conatins same
header file twice or more?

thanks,

sabtain

Hi:
This may be due to a problem that was fixed internally.

The fix was to add a “typedef” in front of the enum for nic_flags
in nicinfo.h:

i.e.
“typedef enum nic_flags (etc.)”

Hope that helps,
R.

sabtain wrote:

Hello,
I am writing a program that needs to include hw/nicinfo.h in more
then one file. Now the problem is everything i build the project, I get
“multiple definitions of” problem. I tried to use extern macro and
ifndef/define macro also to include the header file but nothing is working.
There is no way around but to include the header file in different files.
Can someone please tell me how can I build a project that conatins same
header file twice or more?

thanks,

sabtain

Hello,
after putting this fix, do I still need to do an extern on this
file or can I just do a normal include?

“Robert Craig” <rcraig_at_qnx@nowhere.com> wrote in message
news:f5h5nv$j9v$1@inn.qnx.com

Hi:
This may be due to a problem that was fixed internally.

The fix was to add a “typedef” in front of the enum for nic_flags in
nicinfo.h:

i.e.
“typedef enum nic_flags (etc.)”

Hope that helps,
R.

sabtain wrote:
Hello,
I am writing a program that needs to include hw/nicinfo.h in
more then one file. Now the problem is everything i build the project, I
get “multiple definitions of” problem. I tried to use extern macro and
ifndef/define macro also to include the header file but nothing is
working. There is no way around but to include the header file in
different files. Can someone please tell me how can I build a project
that conatins same header file twice or more?

thanks,

sabtain

Ok a followup:
I added typdef to the enum nic_flags_t. I
included the file nicinfo.h in both .cpp files where I needed it and
compiled. The error is still there at the link time. I still dont understand
why would the linker have objections to the include file in two different
files in a project. It will not even work with extern keyword


“Robert Craig” <rcraig_at_qnx@nowhere.com> wrote in message
news:f5h5nv$j9v$1@inn.qnx.com

Hi:
This may be due to a problem that was fixed internally.

The fix was to add a “typedef” in front of the enum for nic_flags in
nicinfo.h:

i.e.
“typedef enum nic_flags (etc.)”

Hope that helps,
R.

sabtain wrote:
Hello,
I am writing a program that needs to include hw/nicinfo.h in
more then one file. Now the problem is everything i build the project, I
get “multiple definitions of” problem. I tried to use extern macro and
ifndef/define macro also to include the header file but nothing is
working. There is no way around but to include the header file in
different files. Can someone please tell me how can I build a project
that conatins same header file twice or more?

thanks,

sabtain

post post followup:
I included the fix on the corect workspace
on correct momentics box and it worked. Wow, life saver :slight_smile:

Thanks,
“sabtain” <khansx@aecl.ca> wrote in message news:f5haa9$lgq$1@inn.qnx.com

Ok a followup:
I added typdef to the enum nic_flags_t. I
included the file nicinfo.h in both .cpp files where I needed it and
compiled. The error is still there at the link time. I still dont
understand why would the linker have objections to the include file in two
different files in a project. It will not even work with extern keyword


“Robert Craig” <> rcraig_at_qnx@nowhere.com> > wrote in message
news:f5h5nv$j9v$> 1@inn.qnx.com> …
Hi:
This may be due to a problem that was fixed internally.

The fix was to add a “typedef” in front of the enum for nic_flags in
nicinfo.h:

i.e.
“typedef enum nic_flags (etc.)”

Hope that helps,
R.

sabtain wrote:
Hello,
I am writing a program that needs to include hw/nicinfo.h in
more then one file. Now the problem is everything i build the project, I
get “multiple definitions of” problem. I tried to use extern macro and
ifndef/define macro also to include the header file but nothing is
working. There is no way around but to include the header file in
different files. Can someone please tell me how can I build a project
that conatins same header file twice or more?

thanks,

sabtain