Wireshark-dev: Re: [Wireshark-dev] mix of c and C++
From: Helge Kruse <[email protected]>
Date: Tue, 19 Jul 2011 08:23:51 +0200
Am 19.07.2011 07:10, schrieb sagar Guledagudda:
I am compiling it for linux ( xxx.so file )

Includes files are as below

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include<stdio.h>
#include<glib.h>
#include<epan/packet.h>
//      fastfix API
#include<fastapi.h>
#include<string.h>



CC   = g++

CFLAGS = $(INCS)  -fPIC

$(PLUGIN) : $(OBJS)
         mkdir -p $(PLUGIN_DIR)
         $(CC) -shared $(OBJS) $(LIBS)-o [email protected]
%.o : %.cpp
         $(CC) $(CFLAGS) $(LIBS) $<  -o [email protected]
A Unix shared library exports all non-private symbols while a Windows 
dynamic link library exports only the symbols that are defined in the 
export list. To access variables in the Wireshark.so you need to declare 
the symbol 'extern'. You need to declare the symbol as 
'__declspec(dllimport) extern' to access it in the Wireshark.dll.
The config.h defines a macro WS_VAR_IMPORT with the appropriate definition.

If you don't include the config.h WS_VAR_IMPORT is not replaced with anything and your compiler gets confused. If your curious you can check this by *temporarily* change the actual compiler flags and replace -c by -E to get a preprocessed source file. Look for WS_VAR_IMPORT or _NEED_VAR_IMPORT_ in that file.
To solve your problem you should define HAVE_CONFIG_H, probably with

   CFLAGS = $(INCS) -fPIC -DHAVE_CONFIG_H

But the makefiles are usually autogenerated.

@all: What is the sense behind the HAVE_CONFIG_H if I need it anyway?