dll.cpp:
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
void show(){
fprintf(stdout,"%s","dll show call.");
}
#ifdef __cplusplus
}
#endif
dll_1.cpp:
#include "dll.h"
map<string,value> g_map;
int register_funk(string xx,fn_cmd_handler_t fn, string dex) { fprintf(stdout,"%s","core begin\n");
fprintf(stdout,"%u",g_map.size());
fprintf(stdout,"%s","core end\n");
fprintf(stdout,"-------fn-%p",fn);
fprintf(stdout,"%s","----\n");
fprintf(stdout,"%s","----\n");
g_map[xx].fn = fn; g_map[xx].des = dex;
return 0;
}
dll_2.cpp:
#include "dll.h"
int samxxxx( int machine_id, vector<string> &vecValue );
static int __inss = register_funk("xxxx",samxxxx,"funk");
int samxxxx( int machine_id, vector<string> &vecValue )
{
fprintf(stdout,"%s","ssss--------->");
return 0;
}
dll.h:
#ifndef __xxxx__
#define __xxxx__
#include ,map>
#include <vector>
#include <string>
#include <stdio.h>
using namespace std;
typedef int ( *fn_cmd_handler_t )( int machine_id, vector<string> &vecValue );
typedef struct {
fn_cmd_handler_t fn;
string des;
}VALUE;
int register_funk(string xx,fn_cmd_handler_t fn, string dex);
#endif
//and i build this so use
//g++ -g -O2 -shared -Wall -o a.so *.cpp
//the follow is exe file
#include <dlfcn.h>
#include <stdio.h>
int main()
{
void *handle = dlopen("/home/samuel/Temp/funk/a.so", RTLD_LAZY);
fprintf(stdout, "%s\n", dlerror());
dlclose(handle);
return 0;
}
//i build this use
//g++ main.cpp -rdynamic -ldl
when i type this in centos
>./a.out
it core
who can tell me why?
thanks a lot :)