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 通常 ...
随机推荐
- bzoj 2726 任务安排(3)/loj 10184-10186 斜率优化
任务安排1 #include<bits/stdc++.h> #define int long long using namespace std; ; int n,s,t[N],c[N],f ...
- 面向对象 ( OO ) 的程序设计——创建对象
本文地址:http://www.cnblogs.com/veinyin/p/7608000.html 为了避免大量重复代码产生,可采用以下方法创建对象 1 工厂模式 function createP ...
- oracle 远程连接不到dba用户
如果要远程连接192.168.10.44上的oracle,那么192.168.10.44服务器必须启动TNSListener.(配置文件 listener.ora) http://www.111cn. ...
- c# c/s 框架的分页用户控件,还有事件
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; u ...
- 什么是IO多路复用
先百度或者知乎,找到这篇文章 [1] IO 多路复用是什么意思? 文中提到: 第一种好理解,就是来一个请求,fork一个进程,第二种提到I/O多路复用使用单个线程实现的,作者肯定没有写错,因为后面的文 ...
- Coursera, Machine Learning, Neural Networks: Representation - week4/5
Neural Network Motivations 想要拟合一条曲线,在feature 很多的情况下,feature的组合也很多,在现实中不适用,比如在computer vision问题中featu ...
- 第20月第14天 objc_getAssociatedObject _cmd
1. - (CustomNavigationControllerDelegate *)customDelegate { return objc_getAssociatedObject(self, _c ...
- python 的基础 学习 第五天 基础数据类型的操作方法
1,列表的基本操作方法 1,列表是python中的基础数据类型之一,其他语言中也有类似于列表的数据类型,比如js中叫数组,他是以[ ]括起来,每个元素以逗号隔开,而且他里面可以存放各种数据类型比如: ...
- Oracle简单的序列应用
1.序列的简单作用 1.需要自增或自减一个值的时候. 2.为表中的列自动产生值. 3.由用户创建数据库对象,并可由多个用户共享. 4.一般用于主键或唯一列. 2.创建序列的语法及解析 create s ...
- 🍓 JRoll、React滑动删除 🍓
import React, { Component } from 'react'; import '../src/css/reset.css'; import '../src/css/delete.c ...