[关闭]
@snuffles 2015-03-16T13:55:48.000000Z 字数 421 阅读 884

.a

linux


reference
编译Linux使用的.a库文件
链接任意目录下库文件(解决错误“/usr/bin/ld:&nb

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

hello.h

  1. #ifndef __INCLUDE_HELLO_H__
  2. #define __INCLUDE_HELLO_H__
  3. void hello(const charchar *name);
  4. #endif // end __INCLUDE_HELLO_H__

hello.c

  1. #include "stdio.h"
  2. void hello(const charchar *name)
  3. {
  4. printf("Hello world %s\n", name);
  5. }

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

  1. #include "hello.h"
  2. int main()
  3. {
  4. hello("everyone");
  5. return 0;
  6. }

编译出.a的指令
gcc -c hello.c
ar cr libhello.a hello.o
gcc main.c -L -lhello -o main

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注