gcc中__attribute__ ((constructor(101)))做成.a库成功链接
1.cpp:------------------------------------------------
#include
int test() __attribute__ ((constructor(101)));
int test()
{
printf("\n--In lib--");
return 0;
}
test.cpp //没有call 1.cpp中方法,但是希望在main前面先执行test()函数
#include
int main()
{
printf("\n---In main--");
return 0;
}
g++ -c 1.cpp //生成1.o
ar -rcs libanti.a 1.o //生成.a库
g++ test.cpp -Wl,--whole-archive libanti.a -Wl,--no-whole-archive -o main //libanti.a必须全名,不能用-lanti,否则不成功
gcc中__attribute__ ((constructor(101)))做成.a库成功链接的更多相关文章
- GCC的__attribute__ ((constructor))和__attribute__ ((destructor))
通过一个简单的例子介绍一下gcc的__attribute__ ((constructor))属性的作用.gcc允许为函数设置__attribute__ ((constructor))和__attrib ...
- gcc中动态库和静态库的链接顺序
so文件:动态库a文件: 静态库exe文件:可执行程序(linux下以文件属性来标示是否是可执行文件,与后缀名无关) 经过自己写的一些测试程序,大致了解了下gcc中链接顺序问题,总结出以下几点:1,动 ...
- gcc中关于静态库和动态库使用(转)
转自:http://blog.chinaunix.net/uid-25871104-id-3069931.html 1,如何生成静态库 静态库只是一堆object对象的集合,使用ar命令可以将.o文件 ...
- GNU C/C++ __attributes__ GCC中的弱符号与强符号
最近在看一些源代码,遇到了一些使用__attribute__修饰函数和变量的属性方面的代码,不是太了解,很是汗颜,再此做个总结: GCC使用__attribute__关键字来描述函数,变量和数据类 ...
- GCC中初始化函数是怎样被处理的?
本文译至: http://gcc.gnu.org/onlinedocs/gccint/Initialization.html 如我们所知,在GCC通过给代码追加__attribute__((const ...
- GCC中的弱符号与强符号
GCC中的弱符号与强符号 我们经常在编程中碰到一种情况叫符号重复定义.多个目标文件中含有相同名字全局符号的定义,那么这些目标文件链接的时候将会出现符号重复定义的错误.比如我们在目标文件A和目标文件B都 ...
- GCC中的强符号和弱符号及强引用和弱引用
1. 强符号和弱符号 1.1 u-boot和kernel中的__weak指令 u-boot和kernel比较普遍地使用了__weak来定义函数. 在include\linux\compiler-gcc ...
- GCC中-fpic解惑(转载)
参考: 1.<3.18 Options for Code Generation Conventions>2.<Options for Linking>3.<GCC -fP ...
- gcc/g++动态链接库和静态库的链接顺序
转自:http://withc8212.blog.163.com/blog/static/11656983820109263562854/ so文件:动态库a文件: 静态库exe文件:可执行程序(li ...
随机推荐
- 引用 xp系统引导修复(转载)
引用 3592wangxiaoxi 的 xp系统引导修复(转载) 原文来自百度知道a12424106关于“急需xp系统引导方面的知识!”的回复. XP系统的引导过程 如果想学习排除计算机系统故障,首先 ...
- python中multiprocessing.pool函数介绍_正在拉磨_新浪博客
python中multiprocessing.pool函数介绍_正在拉磨_新浪博客 python中multiprocessing.pool函数介绍 (2010-06-10 03:46:5 ...
- 利用MySQL 的GROUP_CONCAT函数实现聚合乘法
MySQL 聚合函数里面提供了加,平均数.最小,最大等,可是没有提供乘法,我们这里来利用MYSQL现有的GROUP_CONCAT函数实现聚合乘法. 先创建一张演示样例表: CREATE TABLE ` ...
- Linux定义系统提示符的变量:PS1
- hdu 4975 A simple Gaussian elimination problem.(网络流,推断矩阵是否存在)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4975 Problem Description Dragon is studying math. One ...
- 为什么我的outlook只能收信不能发信,发送测试电子邮件消息: 无法发送此邮件。请在帐户属性中验证电子邮件
链接地址:http://zhidao.baidu.com/link?url=aVIFo2aNLuHIZGZuEUataHkZp4XApHqyvbEK8ACHPhi3jwhGhM0GBAtm72AnsP ...
- Ext.net.DirectMethods
http://www.ext.net.cn/forum.php?mod=viewthread&tid=1282&highlight=directmethod DirectMethod ...
- 高级UIKit-04(NSUserDefaults、NSKeyedArchiver、对象归档方法)
[day05_1_UserDefault]:判断应用程序是否是第一次运行 NSUserDefaults:用来保存应用程序的配置信息如:程序运行次数,用户登陆信息等. // 使用系统提供的NSUserD ...
- CF 319C(Kalila and Dimna in the Logging Industry-斜率DP,注意叉积LL溢出)
C. Kalila and Dimna in the Logging Industry time limit per test 2 seconds memory limit per test 256 ...
- [TroubleShootin]The backup set holds a backup of a database other than the existing 'xxdb' database.
One: he backup set holds a backup of a database other than the existing 'xxdb' database Sometime ...