12月 312014
 

下面验证我昨天问你的一个问题:

1.c 中调用了 2.c 中的一个static函数;

这里完全可以, gcc –o test 1.c    ; 2.c 是多余的,因为1.c中include了2.c了

 

可能是我哪里错了;

把2.c 编译成一个动态的so文件,改so文件依然导出了这个static的a函数

):

  1. 定义和声明是两个概念
    1. 如果包含了定义的文件,则可以使用static 定义的函数的
    2. 如果包含的是声明的文件(就是都文件),则编译的时候必然需要找到一个外部的该符号
    3. 如果使用static定义的,则,不管编译成 .o 文件还是 .so 文件,该符号是不导出的,外部就是没法用的
  2. 一般来讲
    1. .c 文件和 .h 文件对应出现,.h 中声明外部可以使用的函数,显然不会把static的函数写到.h 中的
    2. 每个 .c 文件都单独编译成一个.o 文件,此时 static 的函数就已经被处理的外部不可见了
 Posted by at 下午 3:03

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

(required)

(required)

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据