test.h代码:
#ifndef __TEST_H_ #define __TEST_H_ void sayHello(void); #endif
test.c代码:
#include <stdio.h> #include "test.h" void sayHello() { printf("Hello my friend.\n"); }
gcc -c test.c -I. ar -r libtest.a test.o
main.c的代码:
#include "test.h" int main(){ sayHello(); return 0; }
gcc main.c -ltest -L. -I.
原文:https://www.cnblogs.com/ziwuxian/p/12589181.html