zoukankan      html  css  js  c++  java
  • 编译Linux使用的.a库文件

    编译Linux使用的.a库文件

    首先是须要编译成.a的源文件

    hello.h

    #ifndef __INCLUDE_HELLO_H__
    #define __INCLUDE_HELLO_H__
    
    void hello(const char *name);
    
    
    #endif // end __INCLUDE_HELLO_H__
    

    hello.c

    #include "stdio.h"
    
    
    void hello(const char *name)
    {
        printf("Hello world %s
    ", name);
    }
    


    和一个在linux平台上做測试的main.c

    #include "hello.h"
    
    
    int main()
    {
        hello("everyone");
        
        return 0;
    }
    


    在Linux上面做測试。编译成.a文件,主要利用.o文件和ar命令


    1、首先生成.o文件:

    gcc -c hello.c

    这样源码的文件夹下就会产生一个hello.o



    2、利用ar命令,从.o文件里创建.a文件

    ar cr libhello.a hello.o

    这样就能够生成.a文件了。注意,所要生成的.a文件的名字前三位最好是lib,否则在链接的时候。就可能导致找不到这个库



    3、在linux下測试使用

    编译main.c。并让hello.a链接到main中

    gcc main.c -L. -lhello -o main(注意这里-L后面有个.)

    这样在当面文件夹以下就出现了可执行程序main。直接执行就是我们索要的结果了



  • 相关阅读:
    E
    C. Connect Three(构造)
    判断矩形相交的方法
    字典树&&01字典树专题&&对字典树的理解
    J
    kmp专题
    Python 字典 popitem() 方法
    Python 字典 pop() 方法
    Python 字典(Dictionary) values()方法
    Python 字典(Dictionary) update()方法
  • 原文地址:https://www.cnblogs.com/cynchanpin/p/6895545.html
Copyright © 2011-2022 走看看