// 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. python+selenium 模拟登陆,自动下单

    目前写的实在太粗糙,留着,以后来写上

  2. Linux常用bash命令

    目录 bash命令 基础操作 export | whereis | which | clear 文件操作 ls | touch | cat | more | head | tail | mv | cp ...

  3. 深入浅出mybatis之入门使用

    写在前面 mybatis是一个持久层框架,可以支持SQL定制和存储过程,实现数据库记录到Java POJO对象之间的映射. 所以说,mybatis是一个ORM框架. 这个ORM可以通过2种方式实现:x ...

  4. [转]java的异常处理最佳实践

    本文转载自 Karibasappa G C (KB), the Founder of javainsimpleway.com, 原文链接 http://javainsimpleway.com/exce ...

  5. 微信小程序开发(3) 热门电影

    在这篇微信小程序开发教程中,我们将介绍如何使用微信小程序开发热门电影及预览功能. 本文主要分为两个部分,小程序主体部分及电影主页和详情页页面部分 一.小程序主体部分 一个小程序主体部分由三个文件组成, ...

  6. ffmpeg安装

    使用 yum 安装nux-dextop 源. 下载:wget http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0- ...

  7. IDAPython教程(三)

    在过去两个部分中,我们已经讨论了使用IDAPython让逆向工程更容易一些.这一部分我们来看一下条件断点. 当在IDA中调试时,分析者经常会遇到希望可以在一个特殊的地址中断下来的情况,但这只有在一些特 ...

  8. gson和fastjson将json对象转换成javaBean 简单对照

    今天在网上看代码时,发现项目使用了Gson,用于将json字符串转换成javaBean. 以前没使用过Gson,随即,简单入了个们, 想起fastjson也有将json字符串转换成javaBean的A ...

  9. 阿里云CentOS7.2卸载CDH5.12

    #####################删除前最好将之前的下载的rpm包和parcels包备份一下##################### 1.停止serviceservice cloudera- ...

  10. kafka为何需要High Available

    一.为何需要replication kafka0.8以前的版本中,是没有Replication的,一旦某一个Broker宕机,则其上所有的partition数据都不可被消费,这与kafka数据持久性及 ...