linux dynamic lib
// test1.h
int a = ;
struct AA
{
int a,b:
};
AA b(5,6);
int ball();
// test1.cpp
# include"test1.h" // the following line is invalid for it will not executed( if it's initialization of a var, it's valid)
// a = 11; int ball()
{
a =;
b = AA(,);
return a+;
}
build a lib with command line : g++ -fPIC -shared test1.cpp -o libtt.so
# include<iostream>
using namespace std; extern int a;
extern int b;
int ball(); int main()
{
cout << " call ball() " << ball() <<endl;
cout << "value of a " << a <<endl;
cout << "value of b" << b << endl;
}
to build an executable with command line: g++ test-main.cpp -L./ -ltt
Notice:
- in test-main.cpp, we can't use " int a" instead of "extern int a", because "int a" is a declaration, which also can be a defination.
- wahile we can use " int ball()" instread of "extern int ball()" because " int ball() " will never be seen as a defination.
- in test1.h, dont define "int a" with prefix ' extern "C" ', because in the symbol table of it's lib, the name of variable is the symbol
- in test-main.cpp, we assume b is of type int and succeeds, because the symbol of b is "b", has no other information
- C or C++ excutable can get the value of a/b; but if C wants to call ball() from a C++ lib, we should add the prifix " extern "C" " to "int ball()"
linux dynamic lib的更多相关文章
- static lib和dynamic lib
lib分为 staticlib 和 dynamic lib: 静态lib将导出声明和实现都放在lib中,编译后所有代码都嵌入到宿主程序, 链接器从静态链接库LIB获取所有被引用函数,并将库同代码一起放 ...
- 设置Linux 程序lib搜索目录
设置Linux 程序lib搜索目录:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:lib路径,例如: export LD_LIBRARY_PATH=$LD_LIBRA ...
- Linux Dynamic Shared Library && LD Linker
目录 . 动态链接的意义 . 地址无关代码: PIC . 延迟版定(PLT Procedure Linkage Table) . 动态链接相关结构 . 动态链接的步骤和实现 . Linux动态链接器实 ...
- linux shared lib 使用与编译
一. 动态链接库的原理及使用 Linux提供4个库函数.一个头文件dlfcn.h以及两个共享库(静态库libdl.a和动态库libdl.so)支持动态链接. Ø ...
- Linux GCC lib库相互引用,互相依赖(交叉引用)链接解决办法
Linux GCC中,如果lib a依赖b,b又依赖a,链接的时候无论a放在前,还是b放在前,都会提示unrefrence. 解决办法就是: 链接的时候a链接两次,即: -la -lb -la
- linux dynamic debug 官方教程
下载内核后,文档在:Documentation/dynamic-debug-howto.txt 中文版本:http://www.oschina.net/translate/dynamic-debug- ...
- linux:/lib/libc.so.6: version `glibc_2.7′ not found【没有解决】采用新方法达到目的
1 下载glibc wget http://ftp.gnu.org/pub/gnu/glibc/glibc-2.7.tar.gz 2. tar zxf glibc-2.7.tar.gz 3. cd g ...
- 入门级的Makefile制作dynamic lib
代码文件结构: . ├── dynamiclib_add.c ├── dynamiclib_mul.c ├── dynamiclibs.h ├── libs └── Makefile 1 direct ...
- 为 Linux 应用程序编写 DLL[转]
自:http://www.ibm.com/developerworks/cn/linux/sdk/dll/index.html 在仅仅只会编写插件的时候为什么要编写整个应用程序? 插件和 DLL 通常 ...
随机推荐
- js 日期 相关
Js计算指定日期加上多少天.加多少月.加多少年的日期 function DateAdd(interval, number, date) { switch (interval) { case " ...
- 设置 Visual Studio IIS Express 站点局域网访问
Ø Visual Stuido 的 IIS Express运行一个网站时,默认地址是这样的:http://localhost:23167/Cache/Three,其中 localhost 表示本机, ...
- PHP面向对象的三大特征操作——封装、继承、多态(下)
<?php 继承(单继承)特点:一个子类只有一个父类,一个父类可以有多个子类.//父类(基类)class Ren{ public $name; public function say ...
- “无法找到XXX.exe的调试信息,或调试信息不匹配”解决方案
错误信息如下: 解决方法: 选择项目属性,依次序进行如下操作. 1.选择 配置属性->链接器->调试->生成调试信息 改为 是 一般问题都是出现在这个地方,修改完了可以尝试运行,若还 ...
- Oracle 11g R2 for Win10(64位)的安装步骤
下载 官网下载地址: win64_11gR2_database_1of2.zip win64_11gR2_database_2of2.zip 将两个压缩包解压到同一个目录下,即"databa ...
- 事件代理on
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Oracle 11g 的 自动内存管理
oracle11g 设置memory_target的值,开启AMM(Auto Memory Management),剩下的Oracle就可以自动维护了 参考:1.https://www.cnblogs ...
- BurpSuite使用笔记
参考:Burp Suite 实战指南 Proxy模块 options--> add 设置监听地址,端口 binding 如果是作为本地浏览器代理默认(127.0.0.1:8080)就可以了. 如 ...
- SQL Server - 索引详细教程 (聚集索引,非聚集索引)
转载自:https://www.cnblogs.com/hyd1213126/p/5828937.html 作者:爱不绝迹 (一)必读:深入浅出理解索引结构 实际上,您可以把索引理解为一种特殊的目录. ...
- 20165231 2017-2018-2 《Java程序设计》第9周学习总结
教材学习内容总结 第十三章 URL类 URL类是java.net包中的一个重要的类,URL的实例封装着一个统一资源定位符(Uniform Resource Locator),使用URL创建对象的应用程 ...