Eclipse for C++ 使用dlopen
来源:互联网 发布:苹果笔记本付费软件 编辑:程序博客网 时间:2024/04/29 07:50
1. 创建名称为dll_test的c++ project, 在Project Type:中选择Shared Library>>Empty Project, 在Toolchains中选择Linux GCC
2. 新建文件foo.cpp, 输入代码如下:
#include <stdio.h>#ifdef __cplusplusextern "C"{#endifvoid foo ( void ){printf("test");}#ifdef __cplusplus}#endif3.新建c++项目main_test, 在Project Type:中选择Executable>>Empty Project, 在Toolchains中选择Linx GCC4.新建文件main.cpp, 输入代码如下:
#include <stdio.h>#include <stdlib.h>#include <assert.h>#include <dlfcn.h>typedef void (*foo)(void);int main(int argc, char * argv[]) {void *handle;char* pszerror;handle = dlopen("libdll_test.so", RTLD_LAZY);pszerror = dlerror();if (0 != pszerror) {printf("%s", pszerror);return 1;}foo func = (foo) dlsym(handle, "foo");pszerror = dlerror();if (0 != pszerror) {printf("%s", pszerror);return 1;}func();dlclose(handle);return (EXIT_SUCCESS);}
5. 如果现在编译main_test项目,会出现没有定义到dlopen的引用的错误,修改配置: 右键点击main_test项目,选择 Properties>>C/C++Build>>Settings>>GCC C++ Linker在右边出现的面板中找到Command line pattern, 然后在最后输入 -ldl, 这时两个项目都可以编译成功,但调试时,你会出现无法找到动态库的错误。
6.配置动态库查找路径, 通过5.的方法,在Command line pattern中,即 -ldl 的后面加入: -Wl,-rpath="../dll_test/Debug/"
OK, 完成,开始调试吧。
- Eclipse for C++ 使用dlopen
- C/C++ 直接使用动态库 dlopen
- dlopen使用
- Eclipse for C/C++(一)简介和简单使用
- dlopen的使用
- eclipse for c/c++
- 【C++】使用MinGW配置Eclipse for C++环境
- JNI 如何使用dlopen,dlsym调用第三方自定义的 .so库( JNI->C,C++)
- C/C++:使用dlopen、dlsym、dlclose运行时装载动态库
- C/C++:多线程下使用dlopen、dlsym、dlclose装载动态库
- C/C++:多进程使用dlopen、dlsym、dlclose装载动态库
- dlopen
- dlopen()
- dlopen
- dlopen
- dlopen
- dlopen与dlsym的使用
- linux下dlopen的使用
- android Application Component研究之BroadcastReceiver
- 卸载SQLServer2005时出现无法读取iismimemap资料表,错误码为-2147024893
- 《那些年啊,那些事——一个程序员的奋斗史》
- 邮件列表的文化与礼节
- 保存图片用。
- Eclipse for C++ 使用dlopen
- 《那些年啊,那些事——一个程序员的奋斗史》转载1到7
- Linux mint如何设置面板位置以及添加面板元素
- BlazeDS:Unknown AMF type '17'
- 项目规划管理
- Android官方开发中心之Web Apps屏幕适配
- [转] 食物相关的英文单词
- 项目规划管理
- android的学习资源