// 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的更多相关文章

  1. static lib和dynamic lib

    lib分为 staticlib 和 dynamic lib: 静态lib将导出声明和实现都放在lib中,编译后所有代码都嵌入到宿主程序, 链接器从静态链接库LIB获取所有被引用函数,并将库同代码一起放 ...

  2. 设置Linux 程序lib搜索目录

    设置Linux 程序lib搜索目录:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:lib路径,例如: export LD_LIBRARY_PATH=$LD_LIBRA ...

  3. Linux Dynamic Shared Library && LD Linker

    目录 . 动态链接的意义 . 地址无关代码: PIC . 延迟版定(PLT Procedure Linkage Table) . 动态链接相关结构 . 动态链接的步骤和实现 . Linux动态链接器实 ...

  4. linux shared lib 使用与编译

    一.              动态链接库的原理及使用 Linux提供4个库函数.一个头文件dlfcn.h以及两个共享库(静态库libdl.a和动态库libdl.so)支持动态链接. Ø        ...

  5. Linux GCC lib库相互引用,互相依赖(交叉引用)链接解决办法

    Linux GCC中,如果lib a依赖b,b又依赖a,链接的时候无论a放在前,还是b放在前,都会提示unrefrence. 解决办法就是: 链接的时候a链接两次,即: -la -lb -la

  6. linux dynamic debug 官方教程

    下载内核后,文档在:Documentation/dynamic-debug-howto.txt 中文版本:http://www.oschina.net/translate/dynamic-debug- ...

  7. 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 ...

  8. 入门级的Makefile制作dynamic lib

    代码文件结构: . ├── dynamiclib_add.c ├── dynamiclib_mul.c ├── dynamiclibs.h ├── libs └── Makefile 1 direct ...

  9. 为 Linux 应用程序编写 DLL[转]

    自:http://www.ibm.com/developerworks/cn/linux/sdk/dll/index.html 在仅仅只会编写插件的时候为什么要编写整个应用程序? 插件和 DLL 通常 ...

随机推荐

  1. 【转载】C# 字符串截取

    https://blog.csdn.net/maba007/article/details/78424760

  2. Java动态代理 深度详解

    代理模式是设计模式中非常重要的一种类型,而设计模式又是编程中非常重要的知识点,特别是在业务系统的重构中,更是有举足轻重的地位.代理模式从类型上来说,可以分为静态代理和动态代理两种类型. 今天我将用非常 ...

  3. C#窗口闪烁问题解决

    https://www.cnblogs.com/AndyDai/p/5203798.html 开发WinForm 程序时经常会遇到闪屏的问题,这会给用户造成很差的使用体验,所以必须妥善解决好这个问题. ...

  4. Javaweb学习笔记——(十八)——————事务、DBCP、C3P0、装饰者模式

    事务     什么是事务?         转账:             1.给张三账户减1000元             2.给李四账户加1000元 当给张三账户减1000元之后,抛出了异常,这 ...

  5. sqlserver 循环取时间

    declare @str date; set @str='2015-01-08'; while DATEDIFF([day], @str , '2015-02-01')>0 begin sele ...

  6. luogu P3235 [HNOI2014]江南乐

    传送门 这题又是我什么时候做的(挠头) 首先是个和SG函数有关的博弈论,SG=0则先手必败.显然一堆石子就是一个游戏,而若干堆石子的SG值就是每堆SG的异或和,所以算出每堆石子SG就能知道答案 然后怎 ...

  7. git 无法拉取新的远程分支

    我们常常会根据远程分支创建本地分支,命令如下 git checkout -b dev origin/dev 上面的命令我是想把远程分支 dev 拉到本地来,但是有时候没有用,提示远程分支不存在,我们需 ...

  8. 360doc个人图书馆解决复制问题

    360doc个人图书馆在复制的时候会弹出如下页面: 对于我们程序员来说很容易就可以推断,可能是在复制的时候写了事件什么的. 估计是这些个: document.oncopy或者document.body ...

  9. 在IntelliJ IDEA 中配置Ueditor富文本插件

    这是我自学的配置教程,刚刚学习不太完善请谅解! 我会根据我的学习进程对此进行更贴,欢迎关注哦 ! 第一步:下载插件,地址:http://ueditor.baidu.com/website/downlo ...

  10. 将List的元素通过中文字符串排序

    类customer public class Customer { public String name; public int age; Customer(String name, int age) ...