c - Expected symbol problems with this function declaration -
i getting c programming realm , having issue think linker related.
i using cmake first time well, adding frustration.
i have included third party header file contains typedef code trying use, , has line:
typedef struct pcap pcap_t;
so code has
pcap_t *var; //later..... var->fd;// line throws error
which throws
error: dereferencing pointer incomplete type
so missing include file, or linker issue? building code in qtcreator , using cmake. can dive on a_t see typedef declaration in included header, can't seem dive on "struct a" see it's coming from.
thanks
edited code above reflect using pcap libraries
so have included in source file's header file following lines
#include <net/bpf.h> #include <pcap/pcap.h>
so guess between these 2 includes, missing defintion of pcap structure. can find it?
thanks
the typedef
statement 2 things. declares existence of of type struct a
. declares a_t
alias struct a
. declaring existence of type without information determine size called c language incomplete type. declaration colloquially referred forward declaration, , type colloquially referred opaque parts of code never see type's definition.
typedef struct a_t; a_t *var;
the c language allows pointers incomplete type defined. pointer incomplete type not incomplete, since pointer type same size void pointer. but, code attempts dereference pointer:
var->member;
since there no definition of struct a
available, compiler has caught error in program, , telling it. not linker issue, semantic error in program.
an opaque type way hide implementation details user of type. is, c's way of providing interface:
typedef struct a_t; a_t *a_create (); void a_destroy (a_t *); int a_get_member (a_t *); void a_set_member(a_t *, int);
then, in code, expected use interface.
a_t *var = a_create(); a_set_member(var, 10); int m = a_get_member(var); a_destroy(var);
the source file implements interface define struct a
looks like. since said had no definition reference in debugger, means did not provide definition anywhere in program.
edit: seems trying use packet capture library. need include <pcap.h>
header file code, , link -lpcap
. if header file or library not exist, need install packet capture development package os. <pcap.h>
has made typedef pcap_t
already, , intentionally opaque. have use interfaces header file defines access information want.
Comments
Post a Comment