本文介绍了静态插入时有关stl Map核心的信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
dll.cpp:
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
void show(){
fprintf(stdout,"%s","dll show call.");
}
#ifdef __cplusplus
}
#endif
dll_1.cpp:
dll_1.cpp:
#include "dll.h"
map<string,value> g_map;
int register_funk(string xx,fn_cmd_handler_t fn, string dex) { // removed obscenity
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; //---------->core at this, why ?? who can tell me????
g_map[xx].des = dex;
return 0;
}
dll_2.cpp:
dll_2.cpp:
#include "dll.h"
int samxxxx( int machine_id, vector<string> &vecValue );
static int __inss = register_funk("xxxx",samxxxx,"funk"); // removed obscenity
int samxxxx( int machine_id, vector<string> &vecValue )
{
fprintf(stdout,"%s","ssss--------->");
return 0;
}
dll.h:
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); // removed obscenity
#endif
//我建立了这个,所以使用
//g ++ -g -O2 -shared -Wall -o a.so * .cpp
//以下是exe文件
//and i build this so use
//g++ -g -O2 -shared -Wall -o a.so *.cpp
//the follow is exe file
//main.cpp
#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建立此用途
//g ++ main.cpp -rdynamic -ldl
当我在centos中键入此内容时
> ./a.out
它核心
谁能告诉我为什么?
非常感谢:)
//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 :)
推荐答案
#include "OtherClass1.h"
#include "OtherClass2.h"
class OtherClass3;
class CDll
{
public:
CDll();
~CDll();
void func();
void func2();
private:
std::map<x,y> m_Map;
int m_BlahBlah;
int m_XXX;
OtherClass1 m_OtherClass1;
OtherClass2 m_OtherClass2;
OtherClass3* m_OtehrClass3;
};
// The only static variable in the DLL
CDll g_Dll;
// functions exported by the shared lib:
void shared_dll_func()
{
g_Dll.func();
}
void shared_dll_func2()
{
g_Dll.func2();
}
...
这篇关于静态插入时有关stl Map核心的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!