C Funktion von C++ aus aufrufen



  • Moin Leute!

    Ich habe folgendes Problem. Ich möchte von C++ aus eine Funktion in C aufrufen. Leider erhalte ich beim Starten des Programms immer die Meldung undefined symbol: mod_foo_test (das ganze ist eine .so-Datei, daher erst beim Start).

    mod_foo.c:

    #include "../include/lighttpd/log.h"
    #include "../include/lighttpd/base.h"
    #include "../include/lighttpd/plugin.h"
    #include "stdio.h"
    #include "stdlib.h"
    #include "../include/lighttpd/buffer.h"
    #include "../include/lighttpd/array.h"
    #include "../include/lighttpd/response.h"
    
    #include "wrapper.h"
    
    #ifdef HAVE_CONFIG_H
    		#include "../include/lighttpd/config.h"
    	#endif
    
    //Hier kommt einiges an initialisierung etc...
    
    INIT_FUNC(mod_foo_init) 
    {
    	plugin_data *p;
        p = calloc(1, sizeof(*p));
    
    	p->match_buf = calloc(1, sizeof(buffer));
    	p->config_storage = NULL;
    
        return p;
    }
    
    //////////////////////////////////////////////////////////////////////////////////////////////
    FREE_FUNC(mod_foo_free) 
    {
        plugin_data *p = p_d;
    
        UNUSED(srv);
    
        if (p->conf.match) free(p->conf.match);
    	if (p->match_buf) free(p->match_buf);
    	if (p) free(p);
    
        return HANDLER_GO_ON;
    }
    //////////////////////////////////////////////////////////////////////////////////////////////
    static void mod_vms_test()
    {
    	system("/usr/bin/ledctl 0 3");
    }
    //////////////////////////////////////////////////////////////////////////////////////////////
    #define PATCH(x) \
    	p->conf.x = s->x;
    static int mod_foo_patch_connection(server *srv, connection *con, plugin_data *p) 
    {	
    	size_t i, j;
    	plugin_config *s = p->config_storage[0];
    
    	PATCH (match);
    
    	// skip the first, the global context 
        for (i = 1; i < srv->config_context->used; i++) 
    	{
    		data_config *dc = (data_config *)srv->config_context->data[i];
            s = p->config_storage[i];
            if (!config_check_cond(srv, con, dc)) 
    			continue;
    
            for (j = 0; j < dc->value->used; j++) 
    		{
    			data_unset *du = dc->value->data[j];
                if (buffer_is_equal_string(du->key, CONST_STR_LEN("vms.match"))) 
    			{
    				PATCH (match);
    			}
    		}
    	}
    	return 0;
    }
    #undef PATCH
    
    //////////////////////////////////////////////////////////////////////////////////////////////
    URIHANDLER_FUNC(mod_foo_uri_handler) 
    {
    	plugin_data *p = p_d;
    	int s_len;
    	size_t k;
    
    	UNUSED(srv);
    
    	if (con->uri.path->used == 0) 
    		return HANDLER_GO_ON;
    
    	mod_foo_patch_connection(srv, con, p);
    
    	if (con->uri.query->used > 0)
    		Hook(con->uri.path->ptr, con->uri.query->ptr);
    	else 
    		Hook(con->uri.path->ptr, "");
    
    	s_len = con->uri.path->used - 1;
    	if (con->conf.log_request_handling) 
    	{
     		log_error_write(srv, __FILE__, __LINE__, "%s", 
    				"-- mod_foo_uri_handler called");
    	}
    
    	for (k = 0; k < p->conf.match->used; k++) 
    	{
    		data_string *ds = (data_string *)p->conf.match->data[k];
    		int ct_len = ds->value->used - 1;
    
    		if (ct_len > s_len) 
    			continue;
    
    		if (ds->value->used == 0) 
    			continue;
    
    		if (0 == strncmp(con->uri.path->ptr + s_len - ct_len, ds->value->ptr, ct_len)) 
    		{
    			con->http_status = 403;
    			return HANDLER_FINISHED;
    		}
    	}
    	/* not found */
    	return HANDLER_GO_ON;
    }
    //////////////////////////////////////////////////////////////////////////////////////////////
    //
    //	Initialisiern des Plugins. Hier werden alle Hooks angegeben, die verwendet werden sollen
    //
    int mod_foo_plugin_init(plugin *p) 
    {
    	p->version = LIGHTTPD_VERSION_ID;
        p->name = buffer_init_string("foo");
        p->init = mod_foo_init;
    	p->handle_uri_clean = mod_foo_uri_handler;
    	p->set_defaults = mod_foo_set_defaults;
        p->cleanup = mod_foo_free;
        p->data = NULL;
    
        return 0;
    }
    

    wrapper.h:

    /*Wrapper-Funktion für Zugriffe aus dem Webserver*/
    #ifdef __cplusplus
    extern "C" 
    {
    #endif
    
    int Init();
    const char* Hook(const char* pUri, const char* pQuery);
    /int Free();
    
    #ifdef __cplusplus
            }
    #endif
    
    void addFoo (int iLevel, const char* lit, const char* sItem);
    

    wrapper.cpp:

    #include "wrapper.h"
    #include "bar.h"
    
    #ifdef __cplusplus
    extern "C" 
    {
    	static void mod_foo_test();
    }
    #endif
    
    static modfoo::Bar* pBar = NULL;
    
    int Init()
    {
      //init something
    }
    
    const char* Hook(const char* pUri, const char* pQuery)
    {
    	//do something
    }
    
    int Free()
    {
      //free something
    }
    
    	void addFoo(int iLevel, const char* lit, const char* sItem)
    	{
    		mod_foo_test();
    
    	}
    

    Ich vermute mal, daß ich die C-Anbindung nicht richtig gelöst habe, aber was mache ich falsch?

    edit: Ach ja, der verwendete Compiler ist gcc, eine Lösung mit "export" fällt somit aus wegen "is nicht..."



  • Verzichte mal auf static bei deinen fraglichen Funktionsdeklarationen bzw. Definitionen. Die kapseln nämlich die Sichtbarkeit.

    static void mod_foo_test();
    

    Was soll das werden?

    /int Free();
    


  • Hallo,

    wo ist mod_foo_test? Ich finde nur mod_vms_test und das ist statric kannst Du also von außen gar nicht aufrufen.

    mfg Martin


Anmelden zum Antworten