Linux动态库的创建和使用

Linux动态库的创建和使用,简单做法如下:

hello.h

#ifndef HELLO_H
#define HELLO_H

void hello(const char *name);

#endif //HELLO_H

hello.c

#include <stdio.h>

void hello(const char *name)
{
printf("Hello %s!/n", name);
}

main.c

#include "hello.h"

int main()
{
hello("everyone");
return 0;
}

创建动态库:

gcc -fPIC -g -c hello.c
gcc -shared -o libmyhello.so hello.o

使用动态库:

gcc -g main.c -L./ -lmyhello -o main








你可能感兴趣的:(Linux动态库的创建和使用)