problem with g_module_symbol



Hello everybody. 

I'm trying to load libraries with g_module_open in windows and linux, I don't have problems in Windows, can load perfectly the libraries. but when I do it in linux tells me that don't find the function 

I am compile mi libmilib.so with
///file1.cpp

float xfun(int d){

	float res;



	res = d * 3;



return res;

}

//milib.h

#ifndef __MILIB_H_

#define __MILIB_H_



float xfun(int d);





#endif

//makefile of libmilib.so
CFLAGS=-Wall -I.



libmilib.so: file1.o 

	ld -o libmilib.so file1.o -shared



file1.o : file1.cpp

	g++ -c $?

//program for load libraries is
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <gtk/gtk.h>

#include <glib.h>

#include <gmodule.h>



typedef float (*xfun)(int d);



xfun auxFun;



int main(){



	GError    **error;

	char xlib[300];

        char namefun[30];

	float res;

        FILE *fp;



	GModule  *milib=NULL;

	error=NULL;

	

        sprintf(xlib,"/home/shadown/Desktop/misProg/make_ejemplos/gmodule/lib/libmilib.so");

	sprintf(namefun,"xfun");



	printf("%s",xlib);



        //fp = fopen(xlib,"rb");

        fp = fopen("libmilib.so","rb");

	if(fp==NULL){

          printf("\nI can open libmilib.so");

        }

	else{

           printf("\nI can't open libmilib.so");

           fclose(fp);

        }



      



	//Check supported

	if(!g_module_supported()){

		printf("\nNo supported\n");

		return 0;

	}



	//Load lib

	milib = g_module_open (xlib, G_MODULE_BIND_LAZY);

	if(!milib){

		printf("\nCan't load library: %s",xlib);

		printf("\nError: %s",g_module_error ());

		printf("\nCan't load modules, You can't use user function\n");

		return 0;

	}

	else{



		//Load function

		if (!g_module_symbol (milib,namefun, (gpointer *)&auxFun)){

			printf("\nUnable load function in: %s",xlib);

			printf("\nError: %s", g_module_error ());

			printf("\nCan't load modules, You can't use user function\n");

			if (!g_module_close (milib)) g_warning ("\nm: %s", g_module_error ());

			return 0;

		}

		else{

			//Use function

			res = auxFun(3);

			printf("\nres = %f",res);

		}

	}



return 0;

}


//Makefile of  main program
CFGTK := `pkg-config --cflags --libs gtk+-2.0 gmodule-2.0`



prog : loadlib.cpp

	g++ ${CFGTK} $? -o prog



And rename function, and made a program that uses the library and works, but when I try to load the function with g_module_symbol, I can not

When I print the error, I have the following:

Error: `xfun': /home/shadown/Desktop/misProg/make_ejemplos/gmodule/lib/libmilib.so: undefined symbol: xfun

the function print between  ( ` )  and ( ' )

I do not know if this error there.

can somebody help me?

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
Regístrate ya - http://correo.yahoo.com.mx/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]