当前位置: 首页 > news >正文

1个空间做2个网站中国河北网站

1个空间做2个网站,中国河北网站,宁波网站建设公司制作网站,电影网站做流量运行时可以自己自定义so库的动态加载框架#xff0c;主动去加载某些库#xff0c;并调用其中的某些方法 首先写一些方法#xff0c;并生成so库 // hello.cpp#include iostream/*使用 nm 命令查看 so 库的内容 */// 1. 使用extern // dlsym(handle, hello主动去加载某些库并调用其中的某些方法 首先写一些方法并生成so库 // hello.cpp#include iostream/*使用 nm 命令查看 so 库的内容 */// 1. 使用extern // dlsym(handle, hello) extern C void hello() {std::cout hello std::endl; }// 2. 不使用extern // dlsym(handle, _Z2hiv) void hi() {std::cout hi std::endl; }// _Z3addi int add(int a) {return a 1; } 编译为so库 c -shared -stdc11 hello.cpp -o hello.so 此时可以通过nm命令看看so库的内容 nm hello.so 0000000000003efc s GCC_except_table38 0000000000003f10 s GCC_except_table43 0000000000003e84 s GCC_except_table6 0000000000003ec4 s GCC_except_table7 0000000000003ed8 s GCC_except_table9U __Unwind_Resume 00000000000032d0 T __Z2hiv 0000000000003300 T __Z3addi 0000000000003ab0 t __ZNKSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE13__get_pointerB7v160006Ev 0000000000003b60 t __ZNKSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE18__get_long_pointerB7v160006Ev 0000000000003b80 t __ZNKSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE19__get_short_pointerB7v160006Ev 0000000000003920 t __ZNKSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE4dataB7v160006Ev 0000000000003b00 t __ZNKSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9__is_longB7v160006Ev 0000000000003540 t __ZNKSt3__113basic_ostreamIcNS_11char_traitsIcEEE6sentrycvbB7v160006Ev 0000000000003bc0 t __ZNKSt3__117__compressed_pairINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE5__repES5_E5firstB7v160006Ev 0000000000003840 t __ZNKSt3__119ostreambuf_iteratorIcNS_11char_traitsIcEEE6failedB7v160006Ev 0000000000003be0 t __ZNKSt3__122__compressed_pair_elemINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE5__repELi0ELb0EE5__getB7v160006Ev 0000000000003d90 t __ZNKSt3__15ctypeIcE5widenB7v160006EcU __ZNKSt3__16locale9use_facetERNS0_2idE 00000000000037b0 t __ZNKSt3__18ios_base5flagsB7v160006Ev 0000000000003c80 t __ZNKSt3__18ios_base5rdbufB7v160006Ev 00000000000038a0 t __ZNKSt3__18ios_base5widthB7v160006EvU __ZNKSt3__18ios_base6getlocEv 00000000000037d0 t __ZNKSt3__19basic_iosIcNS_11char_traitsIcEEE4fillB7v160006Ev 0000000000003c60 t __ZNKSt3__19basic_iosIcNS_11char_traitsIcEEE5rdbufB7v160006Ev 0000000000003cd0 t __ZNKSt3__19basic_iosIcNS_11char_traitsIcEEE5widenB7v160006Ec 0000000000003ca0 T __ZNSt3__111char_traitsIcE11eq_int_typeEii 0000000000003cc0 T __ZNSt3__111char_traitsIcE3eofEv 0000000000003500 T __ZNSt3__111char_traitsIcE6lengthEPKc 0000000000003aa0 t __ZNSt3__112__to_addressB7v160006IKcEEPT_S3_U __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEmc 00000000000038f0 t __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC1B7v160006Emc 0000000000003980 t __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC2B7v160006EmcU __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED1EvU __ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE3putEcU __ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE5flushEvU __ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE6sentryC1ERS3_U __ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEE6sentryD1Ev 0000000000003260 t __ZNSt3__113basic_ostreamIcNS_11char_traitsIcEEElsB7v160006EPFRS3_S4_E 0000000000003bf0 t __ZNSt3__114pointer_traitsIPKcE10pointer_toB7v160006ERS1_ 00000000000038c0 t __ZNSt3__115basic_streambufIcNS_11char_traitsIcEEE5sputnB7v160006EPKcl 0000000000003a90 t __ZNSt3__116__non_trivial_ifILb1ENS_9allocatorIcEEEC2B7v160006Ev 0000000000003560 t __ZNSt3__116__pad_and_outputB7v160006IcNS_11char_traitsIcEEEENS_19ostreambuf_iteratorIT_T0_EES6_PKS4_S8_S8_RNS_8ios_baseES4_ 00000000000039d0 t __ZNSt3__117__compressed_pairINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE5__repES5_EC1B7v160006INS_18__default_init_tagESA_EEOT_OT0_ 0000000000003a10 t __ZNSt3__117__compressed_pairINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE5__repES5_EC2B7v160006INS_18__default_init_tagESA_EEOT_OT0_ 0000000000003df0 t __ZNSt3__118__constexpr_strlenB7v160006EPKc 0000000000003a00 t __ZNSt3__119__debug_db_insert_cB7v160006INS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEEEEvPT_ 0000000000003780 t __ZNSt3__119ostreambuf_iteratorIcNS_11char_traitsIcEEEC1B7v160006ERNS_13basic_ostreamIcS2_EE 0000000000003c00 t __ZNSt3__119ostreambuf_iteratorIcNS_11char_traitsIcEEEC2B7v160006ERNS_13basic_ostreamIcS2_EE 0000000000003a40 t __ZNSt3__122__compressed_pair_elemINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE5__repELi0ELb0EEC2B7v160006ENS_18__default_init_tagE 0000000000003a50 t __ZNSt3__122__compressed_pair_elemINS_9allocatorIcEELi1ELb1EEC2B7v160006ENS_18__default_init_tagE 0000000000003310 t __ZNSt3__124__put_character_sequenceB7v160006IcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_PKS4_m 0000000000003bb0 t __ZNSt3__130__libcpp_is_constant_evaluatedB7v160006EvU __ZNSt3__14coutE 0000000000003280 t __ZNSt3__14endlB7v160006IcNS_11char_traitsIcEEEERNS_13basic_ostreamIT_T0_EES7_U __ZNSt3__15ctypeIcE2idEU __ZNSt3__16localeD1EvU __ZNSt3__18ios_base33__set_badbit_and_consider_rethrowEvU __ZNSt3__18ios_base5clearEj 0000000000003950 t __ZNSt3__18ios_base5widthB7v160006El 0000000000003dc0 t __ZNSt3__18ios_base8setstateB7v160006Ej 0000000000003a70 t __ZNSt3__19allocatorIcEC2B7v160006Ev 0000000000003860 t __ZNSt3__19basic_iosIcNS_11char_traitsIcEEE8setstateB7v160006Ej 0000000000003d60 t __ZNSt3__19use_facetB7v160006INS_5ctypeIcEEEERKT_RKNS_6localeE 0000000000003220 t __ZNSt3__1lsB7v160006INS_11char_traitsIcEEEERNS_13basic_ostreamIcT_EES6_PKcU __ZSt9terminatev 0000000000003890 t ___clang_call_terminateU ___cxa_begin_catchU ___cxa_call_unexpectedU ___cxa_end_catchU ___gxx_personality_v0 00000000000031f0 T _helloU _strlen 可以看到 00000000000032d0 T __Z2hiv 0000000000003300 T __Z3addi00000000000031f0 T _helloU _strlen 动态加载示例代码演示加载 so库so库名为argv[1]并从中读取1个函数函数名为argv[2] 假设该函数格式为 void(*)(void) #include dlfcn.h #include iostream #include unistd.h #include string.h/*** extern C void hello() {std::cout hello std::endl; }void hi() {std::cout hi std::endl; }使用 nm xxx.so 查看函数表(去掉函数前的第一个下划线)对于有 extern C 修饰的C函数dlsym(handle, hello) 对于没有 extern C 修饰的C函数dlsym(handle, _Z2hiv)**/int main(int argc, char* argv[]) {if (argc ! 3) {std::cout dlsym so-path func-name std::endl;return 0;}void* handle dlopen(argv[1], RTLD_NOW);if (handle nullptr) {std::cerr dlopen error: dlerror() std::endl;exit(-1);}dlerror();// FIXME 这里仅演示获取 void(*)(void) 类型的函数void (*func)(void) (void(*)(void))dlsym(handle, argv[2]);if (func nullptr) {std::cerr dlsym error: dlerror() std::endl;exit(-1);}// 调用查找到的函数func();int (*add)(int) (int(*)(int))dlsym(handle, _Z3addi);int r add(1008);std::cout add: r std::endl;int res dlclose(handle);if (res -1) {std::cerr dlclose error: dlerror() std::endl;exit(-1);}return 0; } 要注意原hello.so库中的函数实现是否在方法前有extern C 若有疑问的可以看官方文档 语言链接 - cppreference.com  此处执行3次用来演示extern对于C代码的影响 ./dlsym ./hello.so hello hello add: 1009 ./dlsym ./hello.so hi dlsym error: dlsym(0x7ff90d118010, hi): symbol not found ./dlsym ./hello.so _Z2hiv hi add: 1009 注意 日常中使用动态加载方案时一定要规范好so库的成果物一定要事先确认是否使用extern C
http://www.hkea.cn/news/14290993/

相关文章:

  • 网站开发的职业规划怎样才能做自己的网站
  • 网站引流是什么意思品牌网站建设怎么收费
  • 百度站长seo广告推广怎么赚钱
  • 网站建设 经验网站建设评比标准
  • 网站设计计划书怎么建立自己企业网站
  • 网站开发三剑客海口专业做网站
  • 怎么接做网站私单网站建设 工作室
  • 企业网站建设的请示睢宁网站建设xzqjwl
  • 在线考试系统网站开发港口建设费申报网站
  • 江门免费网站建站模板司法公开网站建设情况汇报
  • 房地产的设计网站建设网站建设后台管理实训报告
  • 建设单位经常去哪个网站东莞市网站建设分站
  • 网站商城建设的维度赣州新闻联播今天回放
  • 网站建站请示app页面制作
  • 黄骅市海边做搜狗手机网站优化快
  • 全国十大网站建设公司排名湖北省建设工程信息网官网
  • 短网址生成站长工具wordpress 去除图片
  • 网站视频下载windows注册公司代理电话
  • 有人用dw做网站吗公司简介范本
  • 惠州建设银行网站crm客户端
  • 成都私人做网站建设网络营销工具及其特点
  • 可做兼职的翻译网站有哪些网站界面的版式架构
  • 企业手机网站建设市场早晨网站建设
  • 网站建建设儿童网站模板免费下载
  • 个人定制网站怎么做陕西省住房与建设厅网站
  • 网站出现弹窗住房和城乡建设部网站统计
  • 西昌有做网站的公司吗wordpress支持页面模版
  • 万江建设网站网站ui设计
  • 外贸公司网站建设费用 如何申请做网站怎么宣传运营
  • apache 创建网站网站设计的流程简答题