shared objects with C++
- From: kpm <kpmkhaja@xxxxxxxxxxxxxx>
- Date: Wed, 26 Sep 2007 08:15:31 -0700
Hi
My goal to build a shared object with a C++ class
should i use always "extern" for all global functions eg
file : helloworld.cpp
---------------------------------
#include "helloworld.h"
extern "C"
{
char name[] = "add";
int world(int i)
{
return i+786;
}
}
file: helloworld.h
------------------------------
#ifndef __hello_world_h
#define __hello_world_h
class helloworld{
public:
helloworld();
~helloworld();
};
#endif
althtough i dont use the class in the code above , i wold like to use
it from teststub.c
/*
* testStub.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
typedef int (*FUNCTION)(int);
int main(void)
{
void* handle = 0;
void (*helloWorld)(void) = 0;
const char* error = 0;
FUNCTION fn;
handle = dlopen("./libhelloworld.so", RTLD_LAZY);
if (0 == handle)
{
error = dlerror();
if (0 != error)
{
fprintf(stderr, "%s\n", error);
}
exit (EXIT_FAILURE);
}
else
{
printf("loaded\n");
}
fn = (FUNCTION)dlsym(handle, "name");
if (0 == helloWorld)
{
error = dlerror();
if (0 != error)
{
fprintf(stderr, "%s\n", error);
exit (EXIT_FAILURE);
}
/* else not an error */
}
//(*helloWorld)();
printf(" %s \n", (*fn)(7));
dlclose(handle);
return (EXIT_SUCCESS);
}
the question is how to access for e.g member function classes from
teststub.c
regards
khaja
.
- Prev by Date: Re: Mathematical models for loop calculations
- Next by Date: Re: Mathematical models for loop calculations
- Previous by thread: Mathematical models for loop calculations
- Next by thread: Unlock the drive
- Index(es):
Relevant Pages
|