A weird problem regarding shared libs...

Venkatakrishnan, V V.Venkatakrishnan@channels.usa.xerox.com
Thu Feb 14 14:00:00 GMT 2002


Hi,
	I've the following files...
/***************************/
/* hello.c */
#include <stdio.h>
#include <dlfcn.h>
void* lib_handle;
const char* (*funcptr)(void);
const char* err_msg;

int main()
{
	printf("Hello World.\n");
	lib_handle=dlopen("./libshared.so",RTLD_LAZY);
	if(!lib_handle)
	{
		printf("Error loading shared library\t %s.\n",dlerror());
		return 0;
	}
	else
	{
		(void*)funcptr=dlsym(lib_handle,"func");
		err_msg=dlerror();
		if(err_msg)
		{
			printf("Error getting pointer to export.\n");
			return 0;
		}
		else
		{
		 	(*funcptr)();	
			dlclose(lib_handle);
		}
	}
	return 1;
}
/*************************************/

/*shrobj.c*/
#include <stdio.h>
const char* func(void)
{
	printf("Printf from shared lib.\n");
}
/************************************/

	now when I do the following
Gcc -c shrobj.c
Gcc -shared -o libshared.so shrobj.o
Gcc hello.c -o Hello
./Hello
	everything works fine.........

Now I basically simply rename the files to change their xtension from ".c"
to ".C" and then use g++ like
G++ -c shrobj.C
G++ -shared -o libshared.so shrobj.o
G++ hello.C -o Hello
./Hello
	gives me this error
Hello World
Error loading shared library	Exec format error.
	
	Any idea why this is happening?  Why exactly am I getting this "Exec
format error", how do I rectify it??

Regards,
Venky



More information about the Gcc-help mailing list