gcc链接参数--whole-archive的作用
来源:互联网 发布:车载导航软件哪个最好 编辑:程序博客网 时间:2024/06/18 10:23
// a.h
extern void foo();
// a.cpp
#include <stdio.h>
void foo()
{
printf("foo\n");
}
// x.cpp
#include "a.h"
int main()
{
foo();
return 0;
}
// Makefile
all: x
x: x.cpp liba.so
g++ -g -o $@ $^
liba.so: liba.a
g++ -g -fPIC -shared -o $@ $^
#g++ -g -fPIC -shared -o $@ -Wl,--whole-archive $^ -Wl,-no-whole-archive
liba.a: a.o
ar cru $@ $^
a.o: a.cpp
g++ -g -c $^
clean:
rm -f x a.o liba.a liba.so
$ make
g++ -g -c a.cpp
ar cru liba.a a.o
g++ -g -fPIC -shared -o liba.so liba.a
#g++ -g -fPIC -shared -o liba.so -Wl,--whole-archive liba.a -Wl,-no-whole-archive
g++ -g -o x x.cpp liba.so
/tmp/cc6UYIAF.o: In function `main':
/data/jayyi/ld/x.cpp:5: undefined reference to `foo()'
collect2: ld returned 1 exit status
make: *** [x] Error 1
默认情况下,对于未使用到的符号(函数是一种符号),链接器不会将它们链接进共享库和可执行程序。
这个时候,可以启用链接参数“--whole-archive”来告诉链接器,将后面库中所有符号都链接进来,参数“-no-whole-archive”则是重置,以避免后面库的所有符号被链接进来。
// Makefile
all: x
x: x.cpp liba.so
g++ -g -o $@ $^
liba.so: liba.a
g++ -g -fPIC -shared -o $@ -Wl,--whole-archive $^ -Wl,-no-whole-archive
liba.a: a.o
ar cru $@ $^
a.o: a.cpp
g++ -g -c $^
clean:
rm -f x a.o liba.a liba.so
- gcc链接参数--whole-archive的作用
- gcc链接参数--whole-archive的作用
- gcc和ld 中的参数 --whole-archive 和 --no-whole-archive
- gcc和ld 中的参数 --whole-archive 和 --no-whole-archive
- gcc和ld 中的参数 --whole-archive 和 --no-whole-archive
- gcc和ld 中的参数 --whole-archive 和 --no-whole-archive
- rdynamic和-whole-archive
- gcc的 -Wl参数的作用
- gcc 链接参数 解释
- gcc链接参数
- gcc的简易用法(编译、参数与链接)
- gcc的简易用法(编译,参数与链接)
- 关于table logging 和 archive log 两个参数对归档日志起到的作用
- GCC的链接问题
- GCC __builtin_expect的作用
- GCC __builtin_expect的作用
- GCC __builtin_expect的作用
- GCC __builtin_expect的作用
- pom.xml
- 给定字典做分词
- WebRTC中最简单loopback摄像头&麦克风的例子
- fragment中onCreateView与onActivityCreated的区别,以及fragment中生命周期的利用
- web前端,jquery对元素及属性进行获取,设置,添加,删除
- gcc链接参数--whole-archive的作用
- sudo and samba file example
- ByteArrayOutputStream用法
- setContentView(R.layout.activity…
- java从http url下载文件
- 弹出DatePickerDialog对话框的操作…
- android gravity用法,我老是记不…
- 依赖服务 factory()在angularJS的用法
- Android多线程断点下载的实现示例