|
|
#ifndef TEST1_H
#define TEST1_H
extern int Add(int,int);
#endif
//test1.c
#include "test1.h"
int Add(int a,int b){
return a+b;
}
//main.c
#include "test1.h"
#include <stdio.h>
main(){
int c = Add(3,5);
printf("result");
}
使用下面命令
gcc -c test1.c
gcc -c main.c
ar cru libtest.a test1.o
gcc -o test1 libtest.a main.o
总是报链接错误,但是最后一行换成
gcc -o test1 main.o libtest.a
就没问题。
请问各位大侠这是什么原因?
另外只用.o文件就不存在这种现象,gcc -o test1 main.o test1.o 和
gcc -o test1 test1.o main.o都ok |
|