Wireshark-dev: Re: [Wireshark-dev] mix of c and C++
From: sagar Guledagudda <sagu072@xxxxxxxxx>
Date: Tue, 19 Jul 2011 15:32:34 +0530
now i am getting linker error like
 
: undefined reference to `proto_register_protocol'
: undefined reference to `proto_register_field_array'
: undefined reference to `proto_register_subtree_array'
: undefined reference to `register_dissector'
: undefined reference to `prefs_register_protocol'
: undefined reference to `prefs_register_uint_preference'
: undefined reference to `prefs_register_string_preference'
: undefined reference to `register_init_routine'
: undefined reference to `register_postseq_cleanup_routine'
 
i have added library path to wireshark/epan where the proto.h is there which contains the above functions. do u have idea abt wat els s required to be done to get through this ?

On Tue, Jul 19, 2011 at 11:53 AM, Helge Kruse <Helge.Kruse-nospam@xxxxxxx> wrote:
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 $@
%.o : %.cpp
        $(CC) $(CFLAGS) $(LIBS) $<  -o $@

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?


___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx>
Archives:    http://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
           mailto:wireshark-dev-request@wireshark.org?subject=unsubscribe