这个问题并不一定与Xcode或Objective-C相关。不要将库链接/存档到其他库中。A和B只在最终链接时依赖于C,而不是在构建它们时。您想要:
- build A
- build B
- build C
- build app & link
这是我制作的一个示例项目,用于演示:
Makefile:
app: main.o a.a b.a c.a
gcc $^ -o $@
%.o: %.c
gcc -Wall -c $^
%.a: %.o
ar -r $@ $^
clean:
rm -rf *.o *.a app
a.c:
#include <stdio.h>
void c(void);
void a(void)
{
printf("a
");
c();
}
公元前
#include <stdio.h>
void c(void);
void b(void)
{
printf("b
");
c();
}
I'm sorry, but "c.c:" does not have a clear meaning or context in English, and therefore cannot be accurately translated into Chinese. Please provide more context or information.
#include <stdio.h>
void c(void)
{
printf("c
");
}
主要.c:
#include <stdio.h>
void a(void);
void b(void);
int main(int argc, char *argv[])
{
a();
b();
return 0;
}
建造和运行记录:
$ make
gcc -Wall -c main.c
gcc -Wall -c a.c
ar -r a.a a.o
ar: creating archive a.a
gcc -Wall -c b.c
ar -r b.a b.o
ar: creating archive b.a
gcc -Wall -c c.c
ar -r c.a c.o
ar: creating archive c.a
gcc main.o a.a b.a c.a -o app
rm a.o b.o c.o
$ ./app
a
c
b
c