在Linux下编译用c编译了一个.a的静态库
在头文件中包含了一个结构体,和一个函数
hello.c
#include <stdio.h>
void hello(const char *name)
{
printf("/Hello %s!\n", name);
}
hello.h
#ifndef HELLO_H
#define HELLO_H
void hello(const char *name);
struct _mc {
int net_number;
};
typedef struct _mc mc_t;
#endif //HELLO_H
基于上述两个文件生成了一个.a的静态库
main.c
#include "hello/inc/hello.h"
int main()
{
mc_t *pmc;
hello("everyone");
return 0;
}
然后再main.c中调用的时候发现。
包含hello.h头文件的时候,可以正常编译并且生成可执行文件。
不包含的时候就会报错,说找不到mc_t这个结构体 的定义。
但是,我把 mc_t *pmc;删掉,
main.c如下
int main()
{
hello("everyone");
return 0;
}
编译成功,且执行文件也可以正常执行。
基于目前的情况来看,linux下生成的.a的静态库,不需要包含头文件,就可以正常调用函数。如果需要调用内部设定的结构体,那么就需要包含对应的头文件了。
网上查了相关的内容
https://www.jianshu.com/p/a30a2e01190d
.a包是一种非开源代码共享程序代码的一种方式,对于接入方而言,看不到具体实现。通常随.a包提供给接入方的还有图片资源包.bundle和提供api接口的.h文件。
两个和我有相识问题的帖子
https://www.cctry.com/thread-246279-1-1.html
https://bbs.csdn.net/topics/390074372?page=1
不知道,有没有办法可以实现不包含头文件就可以调用库里面定义的结构体。