zoukankan      html  css  js  c++  java
  • linux脚本: makefile以及链接库

    Linux makefile 教程 非常详细,且易懂  http://blog.csdn.net/liang13664759/article/details/1771246

    //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("
    ");
    }
    
    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
    ");
      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结果仍同上.

    Makefile以及链接库  http://blog.csdn.net/zkf11387/article/details/8039249

    Makefile 里 -l和-L的区别  http://blog.csdn.net/dreamxu/article/details/6259206

    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中查找函数库

  • 相关阅读:
    P1364 医院设置
    Can you solve this equation?
    HDU 3732 Ahui Writes Word
    2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest H. Delete Them
    2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest J. Bottles
    数据结构--KMP算法总结
    Power Strings(KMP)
    KMP (next数组的性质及证明)
    KMP模板
    poj 3461 Oulipo(KMP模板题)
  • 原文地址:https://www.cnblogs.com/mylinux/p/4962012.html
Copyright © 2011-2022 走看看