//sort.c
#include <stdio.h>
#include <string.h>

void swap(int* a, int* b);
int arry[5] = {1, 4, 5, 23,17};

void show(int * parry, int size)
{
int i = 0;
printf("parry:");
for(i=0; i<size; i++)
{
printf("%d ", parry[i]);
}
printf("\n");
}

void sort(int* parry, int size)
{
int i, j;
int is_sort = 0 ;
for(i = 0; i < size - 1 && !is_sort; i++)
{
for(j = 0; j < size - 1 - i; j++)
{
is_sort = 1;
if(parry[j] > parry[j+1])
{
is_sort = 0;
swap(&parry[j], &parry[j+1]);
}
}
}
}

void old_sort(int* parry, int size)
{
int i, j;

for(i = 0; i< size - 1; i++)
{
for(j = 0; j< size- 1 - i ; j++)
{
if(parry[j] > parry[j+1])
{
swap(&parry[j], &parry[j+1]);
}

}
}
}

void swap(int* a, int* b)
{
if(a==0 || b==0)
{
return;
}

*a = *a ^ *b;
*b = *a ^ *b;
*a = *a ^ *b;
}

int func()
{
show(arry, 5 );
sort(arry, 5 );
show(arry, 5 );
return 0;
}




//main.c
#include <stdio.h>
int main()
{
printf("start main\n");
func();
return 0;
}




#Makefile
a.out: main.o sort.o
gcc -o a.out main.o sort.o
sort.o: sort.c
gcc -o $@ -c $^
main.o : main.c
gcc -o $@ -c $^

clean:
rm -rf *.o a.out



#~/oucaijun/c/>make

make: Warning: File `Makefile' has modification time 43 s in the future

gcc -o main.o -c main.c

gcc -o sort.o -c sort.c

gcc -o a.out main.o sort.o

make: warning: Clock skew detected. Your build may be incomplete.

#~/oucaijun/c/>./a.out

start main

parry:1 4 5 23 17

parry:1 4 5 17 23

#~/oucaijun/c/>make clean

rm -rf *.o a.out


改Makefile:


#Makefile
a.out: main.o sort.o
gcc -o a.out main.o sort.o
*.o: *.c
gcc -o $@ -c $^

clean:
rm -rf *.o a.out


make

make: Warning: File `Makefile' has modification time 85 s in the future

cc -c -o main.o main.c

cc -c -o sort.o sort.c

gcc -o a.out main.o sort.o

make: warning: Clock skew detected. Your build may be incomplete.


改Makefile:


#Makefile
a.out: main.o sort.o
gcc -o a.out main.o sort.o
%.o: %.c
gcc -o $@ -c $^

clean:
rm -rf *.o a.out


make

make: Warning: File `Makefile' has modification time 71 s in the future

gcc -o main.o -c main.c

gcc -o sort.o -c sort.c

gcc -o a.out main.o sort.o

make: warning: Clock skew detected. Your build may be incomplete.

 改Makefile


#Makefile
objs := main.o sort.o
a.out: $(objs)
gcc -o a.out $^
%.o: %.c
gcc -o $@ -c $^

clean:
rm -rf *.o a.out


  make结果仍同上.



objs := main.o sort.o
target := a.out
$(target): $(objs)
# gcc -o $@ $^ #ok
gcc -o $(target) $(objs) #ok
%.o: %.c
gcc -o $@ -c $^

clean:
rm -rf *.o a.out


  make结果仍同上.



gcc -o test test.c -L. -lcrexr64 

-L.表示在当前目录(.)中查找函数库,-lcrexr64表示使用名为libcrexr64.a的函数库

-L/usr/lib -L/opt/app/oracle/product/10.2.0.1/lib 表示在/usr/lib 以及 /opt/app/oracle/product/10.2.0.1/lib中查找函数库