struct redefinition issue with system files
On Mac OS X, I have /usr/include/net/bpf.h and开发者_如何学Python /usr/include/pcap/bpf.h included in my code. Now both of these have some of the same structures defined so I get a redefinition error. I need these both files as they both have some other code that I need. My question is, how do I get this working in my code without having to modify either system file ? Is there a way for me to do this in my code without having to simply create a copy of this header file and use that instead ?
I don't want to modify these files as there are other app's that include only one of these 2 file's and would need the structure's defined. Thanks in advance.
Some header files have #define
s in place for exactly such cases. For instance in windows, if you want to use winsock2 and have windows.h you need to do:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
Otherwise the definitions of winsock1 which are included in windows.h would clash with winsock2. I doubt however that this is the case with pbf.h
. this patten doesn't occur so much in unix.
The last resort options is to decide which header file you need more of, remove the second one and add the definition you're missing by hand,y copy-pasting it from the second. You might want to write a small script that does the copy-pasting for you based on the names of the functions so it won't be as fragile.
精彩评论