没有 RTOS/OS 的小型嵌入式系统是否使用动态/共享库。我的理解是,它很难使用,而且不会有成效。
如果我们多次调用静态库中存在的 API。API 代码是否将放置在每个调用位置,例如宏扩展或代码/文本对于所有调用都是通用的。我认为代码/文本会很常见。
如果我为具有多个 API 的 .c 文件创建了一个静态库,并且我将它与主文件静态链接,并且在主文件中只调用了一个 API,所以我的问题是整个库是否包含在最终的 .bin 中或仅包含特定的 API 代码。
从上述问题中,您可以假设我本身缺少基础知识,因此任何人都可以提供相关链接来复习这些内容。
问候
[编辑]
我尝试过以下事情
add.c 模块
`int addition(int a,int b)`
`{`
`int result;`
`result = a + b;`
`return result;`
`}`
`size addition.o`
23 0 0 23 17 addition.o
乘法.c 模块
`int multiplication(int a, int b)`
`{`
`int result;`
`result = a * b;`
`return result;`
`}`
`size multiplication.o`
21 0 0 21 15 multiplication.o
创建两者的目标文件并放入存档
ar cr libarith.a addition.o multiplication.o
然后静态链接到我的主应用程序
example.c 模块
`#include "header.h"`
`#include <stdio.h>`
`1:int main()`
`2:{`
`3:int result;`
`4:result = addition(1,2);`
`5:printf("addition result is : %d\n",result);`
`6:result = multiplication(3,2);`
`7:printf("multiplication result is : %d\n",result);`
`8:return 0;`
`9:}`
gcc -static example.c -L. -larith -o example
size of example
511141 1928 7052 520121 7efb9 example
注释了 example.c 的第 6 行
并再次链接
gcc -static example.c -L。-larith -o example
size of example
511109 1928 7052 520089 7ef99 example
以上两个之间的差异为 32 个字节,
这意味着 add.o 不包括在示例中
将模块 add.c 和 multiplication.c 合并为 addmult.c 如下
int addition(int a,int b)
{
int result;
result = a + b;
return result;
}
int multiplication(int a, int b)
{
int result;
result = a * b;
return result;
}
创建目标文件并在
执行此操作之前放入存档我已删除以前
的存档 ar cr libarith.a addmult.o
现在注释了 example.c
gcc -static example.c -L 的第 6 行。-larith -o 示例
大小示例
511093 1928 7052 520073 7ef89 示例未
注释的第 6 行 example.c
大小示例 511141 1928 7052 520121 7efb9 示例
我的问题是在这两种情况下,如果两个函数都被调用,最终文本大小是相同的,但如果只调用一个函数,则差异为 16,但 multiplication.o 大小为 23,所以肯定不包括在内,但我们将如何证明 16 是合理的。如果我缺少一些基本知识本身?